热门

最新

红包

立Flag

投票

同城

我的

发布
qq_52152909
biubiu崽
5 年前
trueqq_52152909

懵逼了,主函数老是出现未定义标识符的错误。

分析和运行下面的程序,注意友元函数dist(point a,point b)的作用。将友元函数dist(point a,point b)改为Point类的公有成员函数Point ::dist(point &b),请修改主函数中的相应代码,使程序功能不变。
#include <iostream>
#include <cmath>
using namespace std;
class Point
{
double x;
double y;
public:
Point(double a,double b)
{
x=a;
y=b;
}
friend double dist(Point a,Point b);
};
double dist(Point a,Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

void main()
{
Point p1(1,2);
Point p2(5,2);
cout<<dist(p1,p2)<<endl;
}

CSDN App 扫码分享
分享
评论
点赞
打赏
  • 复制链接
  • 举报
下一条:
我用#CSDN#这个app发现了有技术含量的博客,小伙伴们求同去《安装 | MATLAB2018a (64位) 安装教程及安装包下载链接》, 一起来围观吧 https://blog.csdn.net/u011344545/article/details/84971945?utm_source=app
立即登录