class test{
2 int mvalue;
3 public:
4 test(int i){
5 cout << "test(int i) =" << i << endl;
6 mvalue = i;
7 }
8 int value(){
9 return mvalue;
10 }
11 test& operator++(){
12 ++mvalue;
13 return *this;
14 }
15 //后++
16 int operator++(int){
17 cout << "int opertor++" << endl;
18 int ret = mvalue;
19 cout << "mvalue=" << mvalue << endl;//0
20 mvalue++;
21 cout << "mvalue=" << mvalue << endl;//1
22 cout << "ret=" << ret << endl;
23 return ret;
24 }
25 };
26 int main(){
27 test t(0); //test(int i) = 0
28 test tt = t++; //int opertor++; mvalue=0;mvalue=1;ret=0;test(int i) = 0;
29
30 cout << tt.value() << endl; //0
31 cout << t.value() << endl; //1
32 return 0;
33 //运行结果
34 test(int i) =0
35 int opertor++
36 mvalue=0
37 mvalue=1
38 ret=0
39 test(int i) =0
40 0
41 1