#include "iostream.h"
#include "math.h"
#include "conio.h"
class Point
{
int X,Y;
public:
Point(int x=0,int y=0)
{ X=x; Y=y; }
Point(Point &p);
int Getx() { return X; }
int Gety() { return Y; }
void disp()
{ cout<<"("<<X<<","<<Y<<")"; }
};
Point::Point(Point &p)
{
X=p.X;
Y=p.Y;
cout<<"Point 复制构造函数被调用"<<endl;
}
class Distance
{
private:
Point p1,p2;
double dist;
public:
Distance(Point xp1,Point xp2);
double Getdis() { return dist; }
};
Distance::Distance(Point xp1,Point xp2)
{
cout<<"Distance 构造函数被调用"<<endl;
double x=double(xp1.Getx()-xp2.Getx());
double y=double(xp1.Gety()-xp2.Gety());
dist=sqrt(x*x+y*y);
}
void main()
{
Point p1(1,2),p2(8,6);
Distance d(p1,p2);
p1.disp();
cout<<"和";
p2.disp();
cout<<"两个点的距离:"<<d.Getdis()<<endl;
getch();
}
//先你们看下运行结果,看能不能输出四个Point复制函数被调用的情况//