马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
#include<cmath>
using namespace std;
class point
{
public:
point(int xx=0,int yy=0)
{
x=xx;
y=yy;
}
point(point &p);
int getX() {return x;}
int getY() {return y;}
private:
int x,y;
};
point::point(point &p)
{
x=p.x;
y=p.y;
cout<<"calling the copy cnstructor"<<endl;
}
class line {
public:
line(point xp1,point xp2);
line(line &1);
double getlen() {return len;}
private:
point p1,p2;
double len;
};
line::line(point xp1,point xp2):p1(xp1),p2(xp2){
cout<<"calling constructing of line"<<endl;
double x=static_cast<double>(p1.getX()-p2.getX());
double y=static_cast<double>(p1.getY()-p2.getY());
len=sqrt(x*x+y*y);
}
line::line(line &1):p1(1,p1),p2(1,p2){
cout<<"calling the copy constructor of line"<<endl;
len=1.len;
}
int main()
{point myp1(1,1),myp2(4,5);
line line(myp1,myp2);
line line2(line);
cout<<"the length of the line is :"<<line.getlen();
cout<<"the length of the line 2is :"<<line.getlen();
return 0;
}
|