#include
#include
using namespace std;
class point;
class line
{
public:
float dis(point &pt1,point &pt2);
};
class point
{
private:
int x,y;
friend float line::dis(point &pt1,point &pt2); //这边为什么要使用:: ?//因为你要给point类定义line类中的方法的友元,所以需要用::来指明是哪一类中哪一个方法为友元。
public:
point(int i=0,int j=0)
{
x=i;
y=j;
}
void disp()
{
cout<<"("<
};
int main()
{
line line1;
point pt1(1,2),pt2(3,4);
pt1.disp();
cout<<"与";
pt2.disp();
cout<<"距离="<
}
float line::dis(point &pt1,point &pt2)
{
float d;
d=(float)sqrt((pt1.x-pt2.y)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y));
return d;
}