C++ 重载运算符

struct point
{
    double x, y;
    point(double _x, double _y):x(_x), y(_y){}
    
    // 点-点=向量
    point operator-(const point &v){
        return point(x-v.x, y-v.y);
    }
    
    int dcmp(double x)const{
        if (fabs(x)<eps) return 0;
        else return x<0?-1:1;
    }
    bool operator == (const point &v)const{
        return (dcmp(x-v.x)==0 && dcmp(y-v.y)==0); 
    }
};

 

posted @ 2018-05-02 16:55  楼主好菜啊  阅读(112)  评论(0编辑  收藏  举报