C++重载
一、重载前后缀符号
(1)前缀(副作用马上生效)
- 返回值是int & 类型
int & int::operator++()
{
*this +=1;//新版本
return *this;//马上返回新版本
} (2)后缀(副作用不马上生效)
- 返回值是const int类型
const int int::operator++(int)
{
int oldValue = *this;//先保存老版本
++(*this);
return oldValue;//返回老版本
} 
京公网安备 11010502036488号