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

原文地址:https://www.cnblogs.com/zhangyanguang/p/4945832.html