📄 507.cpp
字号:
//507.CPP
//demo friend function
#include <iostream.h>
#include <math.h>
class P //Point
{
friend double Dist(const P& p1,const P& p2);
int x,y;
public:
P(){ x = 0; y = 0 ;}
P(int a,int b)
{ x = a; y= b; }
};
double Dist(const P& p1,const P& p2)
{
double dx = p1.x - p2.x;
double dy = p1.y - p2.y;
return sqrt(dx*dx + dy*dy);
}
int main()
{
P p1,p2(3,4); //两个对象
cout << Dist(p1,p2)<< endl;
return 0;
}
/*
5
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -