#include
#include
using namespace std;
class Point
{
public:
Point(int X,int Y)
{x=X;y=Y;cout<<"Point带参构造函数调用完毕!"<<x<<ends<<y<<endl;}
~Point(){cout<<"Point析构函数调用完毕!"<<x<<ends<<y<<endl;}
Point(Point &P){x=P.x;y=P.y;cout<<"Point拷贝构造函数调用完毕!"<<x<<ends<<y<<endl;}
int getX(){return x;}
int getY(){return y;}
private:
int x,y;
};
class Line
{
private:
Point p1,p2;
double dist;
public:
Line(Point P1,Point P2);
Line(Line &L);
~Line(){cout<<"Line析构函数白调用!"<<endl;}
double getDist(){return dist;}
};
Line::Line(Point P1,Point P2):p1(P1),p2(P2)//传值方式,会建立副本。
{
cout<<"Line构造函数调用完毕!"<<endl;
double dx=double(p1.getX()-p2.getX());
double dy=double(p1.getY()-p2.getY());
dist=sqrt(dx*dx+dy*dy);
}
Line::Line(Line &L):p1(L.p1),p2(L.p2)
{ cout<<"Line拷贝构造函数调用完毕!"<<endl;dist=L.dist;}
int main()
{
Point myp1(1,2),myp2(4,5);
Line myL(myp1,myp2);
// cout<<"the distance is:"<<myL.getDist()<<endl;
// Line youL(myL);
// cout<<"the diatance is"<<youL.getDist()<<endl;
return 0;
}
请问红框里面四行顺序为什么是这样的?![