#include <iostream>
#include <cmath>
using namespace std;
class CPoint
{
private:
double x; // 横坐标
double y; // 纵坐标
public:
CPoint(double xx=0,double yy=0):x(xx),y(yy){}
double distance1(CPoint &); //成员函数的声明、
friend double distance2(CPoint &,CPoint &);
double getx(){return x;}
double gety(){return y;}
};
double distance3(CPoint &,CPoint &); //一般函数声明
double CPoint::distance1(CPoint &p)
{
return (sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y)));
}
double distance2(CPoint &p1,CPoint &p2)
{
double x=p1.x-p2.x;
double y=p1.y-p2.y;
return (sqrt((x*x)+(y*y)));
}
double distance3(CPoint &p1,CPoint &p2)
{
double x=p1.getx()-p2.getx();
double y=p1.gety()-p2.gety();
return (sqrt((x*x)+(y*y)));
}
int main()
{
CPoint p1(1,1), p2(0,0);
cout<<p1.distance1(p2)<<endl;
cout<<distance2(p1,p2)<<endl;
cout<<distance3(p1,p2)<<endl;
system("pause");
return 0;
}