friend function
时间:2010-06-03 来源:checl1987_EE
#include<stdio.h>
#include<math.h>
class Point
{
public:
Point(int xx, int yy){X = xx, Y = yy;}
int GetX() const {return X;}
int GetY() const {return Y;}
friend float fDist(Point &a, Point &b); //friend func
private:
int X, Y;
};
float fDist(Point &a, Point &b)
{
float x = a.X - b.X; //can use class private ptr.
float y = a.Y - b.Y;
float len = sqrt(x*x + y*y);
return len;
}
int main(int argc, char *argv[])
{
Point a(1, 2), b(3, 4);
printf("len is %f\n", fDist(a, b));
return 0;
}
相关阅读 更多 +