#include<iostream>
#include<math.h>
using namespace std;
class Point
{
private:
double x;
double y;
public:
Point(double a,double b)
{
x = a;
y = b;
}
int GetPoint()
{
cout<<"("<<x<<","<<y<<")";
return 0;
}
friend double Distance(Point &a,Point &b);//必须在类内对友元函数声明
};
//求两点之间的距离
double Distance(Point &a,Point &b)
{
double xx;
double yy;
xx = a.x-b.x;
yy = a.y-b.y;
return sqrt(xx*xx+yy*yy);
}
int main()
{
Point A(2.0,3.0);
Point B(1.0,2.0);
double dis;
dis = Distance(A,B);
cout<<dis<<endl;
return 0;
}
友元函数的使用
最新推荐文章于 2022-05-04 21:16:17 发布