Advertisement

对类Point 重载+10(向增)、-1(白减)运算符,要求同时支持前缀和后缀形式

阅读量:

#include

using namespace std;

class Point

{

private:

int _x;

int _y;

public:

Point(int x=0,int y=0):_x(x),_y(y) {

_x = x;

_y = y;

}

void show() const;

Point& operator++(); //前置

Point& operator--(); //前置

Point operator++ (int); //后置

Point operator--(int); //后置

~Point() {};

};

Point & Point::operator++()

{

_x += 1;

_y += 1;

return Point(_x, _y);

}

Point & Point::operator--()

{

_x -= 1;

_y -= 1;

return Point(_x, _y);

}

Point Point::operator++(int)

{

_x = _x;

_y = _y;

return *this; // TODO: 在此处插入 return 语句

}

Point Point::operator--(int)

{

_x = _x;

全部评论 (0)

还没有任何评论哟~