源代码:#include<iostream> #include<cmath> using namespace std; class Point{ public: Point(){x=0;y=0;}; Point(int x,int y){this->x=x;this->y=y;} Point(const Point& p){x=p.x;y=p.y;} int Getx(){return x;} int Gety(){return y;} friend float Getline(Point& p1,Point& p2); private: int x,y; }; float Getline(Point& p1,Point& p2){ float dx=p1.x-p2.x; float dy=p1.y-p2.y; return sqrt(dx*dx+dy*dy); } int main(){ Point p1(3,5),p2(4,6); double d=Getline(p1,p2); cout<<d<<endl; } 第二种 友元类 分享知识,分享快乐!希望中国站在编程之巅! ----融水公子 |
|