运算符++ 重载

 


class Point{
public:
    float _x;
    float _y;
    Point(float x,float y):_x(x),_y(y){};
    //前缀,和普通的单目运算符重载一样,!a
    Point operator++(){
        this->_x++;
        this->_y++;
        return *this;
    }

    //重载后缀++
    Point operator++(int){
        Point yy=*this;
        this->_x++;
        this->_y++;

        return yy;
    }

    //前缀
    Point operator--(){
        this->_x--;
        this->_y--;
        return *this;
    }

    Point operator--(int){
        Point yy=*this;
        this->_x--;
        this->_y--;

        return yy;
    }

};

 

你可能感兴趣的:(C/C++)