123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include <iostream>
- class Point {
- private:
- int _x;
- int _y;
- public:
- Point(int x, int y) : _x(x), _y(y) {}
- Point& operator++() {
- _x++;
- _y++;
- return *this;
- }
- Point operator++(int) {
- Point temp = *this;
- _x++;
- _y++;
- return temp;
- }
- Point& operator--() {
- _x--;
- _y--;
- return *this;
- }
- Point operator--(int) {
- Point temp = *this;
- _x--;
- _y--;
- return temp;
- }
- void display() {
- std::cout << "(" << _x << ", " << _y << ")";
- }
- };
- int main() {
- int x, y;
- std::cin >> x >> y;
- Point point(x, y);
- Point temp0 = point;
- temp0.display();
- std::cout << std::endl;
-
- // 后置和前置“++”运算
- Point temp1 = point++;
- temp1.display();
- std::cout << std::endl;
-
- ++point;
- point.display();
- std::cout << std::endl;
- // 后置和前置“--”运算
- Point temp2 = point--;
- temp2.display();
- std::cout << std::endl;
- --point;
- point.display();
- std::cout << std::endl;
- return 0;
- }
|