⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch18_4.cpp

📁 上面的程序是关于钱能的C++课后习题答案
💻 CPP
字号:
//**********************
//**    ch18_4.cpp    **
//**********************

#include <iostream.h>

class Increase{
public:
  Increase(int x):value(x){}
  Increase & operator++();      //前增量
  Increase operator++(int);     //后增量
  void display(){ cout <<"the value is " <<value <<endl; }
private:
  int value;
};

Increase & Increase::operator++()
{
  value++;                      //先增量
  return *this;                 //再返回原对象
}

Increase Increase::operator++(int)
{
  Increase temp(*this);         //临时对象存放原有对象值
  value++;                      //原有对象增量修改
  return temp;                  //返回原有对象值
}

void main()
{
  Increase n(20);
  n.display();
  (n++).display();              //显示临时对象值
  n.display();                  //显示原有对象
  ++n;
  n.display();
  ++(++n);
  n.display();

  (n++)++;                      //第二次增量操作对临时对象进行
  n.display();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -