
- 原题题目
- 代码实现
- 提交结果
原题题目
代码实现
#include
using 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();
}
提交结果
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)