📄 ch18_4.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 + -