友元函数
#include<iostream.h>
#include<cmath>
class Long
{
private:
double x;
double y;
public:
Long(double xx=0,double yy=0):x(xx),y(yy){}
void distance1(Long &);
friend void distance2 (Long &,Long &);
int getx()
{
return x;
}
int gety()
{
return y;
}
};
void Long::distance1(Long &t)
{
cout<<sqrt((this->x-t.x)*(this->x-t.x)+(this->y-t.y)*(this->y-t.y))<<endl;
}
void distance2 (Long &t1,Long &t2)
{
cout<<sqrt((t1.x-t2.x)*(t1.x-t2.x)+(t1.y-t2.y)*(t1.y-t2.y))<<endl;
}
void distance3 (Long &t1,Long &t2)
{
cout<<sqrt((t1.getx()-t2.getx())*(t1.getx()-t2.getx())+(t1.gety()-t2.gety())*(t1.gety()-t2.gety()))<<endl;
}
int main()
{
Long L1(4,6),L2(2,3);
L1.distance1(L2);
distance2(L1,L2);
distance3(L1,L2);
return 0;
}