Chinaunix首页 | 论坛 | 博客
  • 博客访问: 567770
  • 博文数量: 213
  • 博客积分: 6789
  • 博客等级: 准将
  • 技术积分: 1947
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-01 17:11
文章分类

全部博文(213)

文章存档

2012年(9)

2011年(62)

2010年(99)

2009年(43)

分类: C/C++

2010-06-03 12:25:50

#include
#include
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;
}
阅读(883) | 评论(0) | 转发(0) |
0

上一篇:use same name function

下一篇:const

给主人留下些什么吧!~~