#include <iostream>
using namespace std;
class amount
{
public:
amount()
{
n=0;
}
amount(int x)
{
n=x;
}
unsigned int n;
amount& operator ++() // 这是前缀++运算符
{
n++;
return *this;
}
amount & operator ++(int x) //这个是后缀++运算符
{
n++;
return *this;
}
};
int main()
{
amount a(1);
cout<<a.n<<endl;
++a;
a++;
cout<<a.n<<endl;
return 0;
}
这个代码还不是很规范,主要是运算符重载函数返回值问题,详细版见 http://st251256589.blog.163.com/blog/static/16487644920110603543321/