c++友元函数和友元类

#include <iostream>
using namespace std;
class Point  
{  
public:  
    Point(double xx, double yy) { x=xx; y=yy; }  
    friend double Distance(Point &a, Point &b);  
private:  
    double x, y;  
};  
double Distance(Point &a, Point &b)  
{  
    double dx = a.x - b.x;  
    double dy = a.y - b.y;  
    return sqrt(dx*dx+dy*dy);  
}  

void main(){
    Point p1(1,2),p2(2,3);
    double d=Distance(p1,p2);
    cout<<d<<endl;


}

http://www.cnblogs.com/fzhe/archive/2013/01/05/2846808.html

posted @ 2015-11-07 18:22  爱读书de小学生  阅读(193)  评论(0编辑  收藏  举报