- 原题题目
- 代码实现
- 提交结果
原题题目
代码实现
#includeusing namespace std; class Point { public: Point() : x_(0), y_(0) {} Point(const int x__, const int y__) : x_(x__), y_(y__) {} Point(const Point& other) { x_ = other.x_; y_ = other.y_; } Point& operator++() { ++x_; ++y_; return *this; } Point operator++(int) { Point tmp(*this); ++(*this); return tmp; } Point& operator--() { --x_; --y_; return *this; } Point operator--(int) { Point tmp(*this); --(*this); return tmp; } void display() const { cout << '(' << x_ << ',' << y_ << ')' << endl; } private: int x_; int y_; }; int main() { Point a,b(5,5); a = b++; a.display(); a = ++b; a.display(); a = --b; a.display(); a = b--; a.display(); }
提交结果



