c++ 运算符重载之成员函数重载

1成员函数重载

#include
#include
using namespace std;
class Cycle;
class Point{
    double x,y;
    public:
    Point()=default;
    Point(double rx ,double ry)
        :x(rx),y(ry){}
    ~Point(){}
    double get_x(){return x;}
    double get_y(){return y;}
friend double get_p2p(Point p1,Point p2);
friend double get_p2c(Point p, Cycle c);
    friend class Cycle;//友元类
};
class Cycle{
    Point cp;
    double /*x,y,*/r;
    public:
    Cycle()=default;
    Cycle(double rx ,double ry, double rr):/*(cp.x)(rx),(cp.y)(ry),*/r(rr){
    cp.x=rx;cp.y=ry;
    }
    ~Cycle(){}
friend double get_p2c(Point p, Cycle c);
    double get_area(){return 3.14*r*r};
    double get_area(double pi){return pi*r*r};
};
double get_p2p(Point p1,Point p2)
{
    double lx=p1.x-p2.x;
    double ly=p1.y-p2.y;
    double line = sqrt(lx*lx + ly*ly);
    return line;
}

double get_p2c(Point p, Cycle c)
{
    double lx=p.x-c.cp.x;
    double ly=p.y-c.cp.y;
    double line = sqrt(lx*lx + ly*ly);

    return fabs(line -c.r);
}

int main()
{
    return 0;
}

你可能感兴趣的:(c++,c++-运算符重载)