C++课后作业 19. 教材习题8

C++课后作业 19. 教材习题8,第1张

文章目录
    • 原题题目
    • 代码实现
    • 提交结果


原题题目


代码实现
#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();
}

提交结果

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/921203.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-16
下一篇2022-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存