袁辉勇 5=2 友元函数

1==     friend double dist(point p1, point p2 );
#include <iostream>
#include<cmath> 
using namespace std;

class point
{
    int x,y;   

public:        
    friend    double dist(point p1, point p2 );                 
    point(int xx,int yy)                              {  x=xx;      y=yy;  }
};

double dist(point p1 ,point p2 )
{
    double xxx=p1.x-p2.x  ,  yyy=p1.y-p2.y ;
    return sqrt(xxx*xxx + yyy*yyy) ;
}


int main()
{
    point p1(0,0),p2(3,4);
    cout<<dist(p1,p2)<<endl;
}






#include <iostream>
#include<cmath> 
using namespace std;

class point
{
    int x,y;   
friend    double dist(point p1, point p2 );     

public:                      
    point(int xx,int yy)   {  x=xx;      y=yy;  }
};



double dist(point p1 ,point p2 )
{
    double xx=p1.x-p2.x  ,  yy=p1.y-p2.y ;
    return sqrt(xx*xx + yy*yy) ;
}


int main()
{
    point p1(0,0),p2(3,4);
    cout<<dist(p1,p2)<<endl;
}



C++ 文章被收录于专栏

C++谭浩强 冯博强 贾应知 袁辉勇

全部评论

相关推荐

李橙子:结果虽不够理想,但过程本身已是宝贵的淬炼。能把学习机会放在薪酬之前,证明你目光长远。先踏实进去,用这段时间扎实学好Python后端,把公司项目吃透,你的价值会在下一份工作中完全体现。这个起点,值得。
点赞 评论 收藏
分享
脑袋锈住了:你这算啥,哥们中科院中强所硕士,本科211,叫我去干分拣,时薪20
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务