友元函数

来源:互联网 发布:上市公司研发费用数据 编辑:程序博客网 时间:2024/05/23 11:05
#include <iostream>#include<cmath>using namespace std;class Cpoint{private:    double x;    double y;public:    Cpoint(double xx=0,double yy=0):x(xx),y(yy){}    void setx(double xx);    void sety(double yy);    double putx();    double puty();    friend void showCpoint(Cpoint &a,Cpoint &b);};void Cpoint::setx(double xx){    x=xx;}void Cpoint::sety(double yy){    y=yy;}double Cpoint::putx(){    return x;}double Cpoint::puty(){    return y;}void showCpoint(Cpoint &a,Cpoint &b){    double x=a.x-b.x;    double y=a.y-b.y;    cout<<sqrt(x*x+y*y)<<endl;}void show(Cpoint a,Cpoint b){    double x=a.putx()-b.putx();    double y=a.puty()-b.puty();    cout<<sqrt(x*x+y*y)<<endl;}int main(){    Cpoint a(3,3),b(1,1);    show(a,b);    showCpoint(a,b);    return 0;}

0 0