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