1
#include<iostream> 2 using namespace std; 3 class test{ 4 int mvalue; 5 public: 6 test(int i){ 7 mvalue = i; 8 } 9 int value(){ 10 return mvalue; 11 } 12 test& operator++(){ 13 ++mvalue; 14 return *this; 15 } 16 //后++ 17 test operator++(int){ 18 //临时对象 19 test ret(mvalue); 20 mvalue++; 21 return ret; 22 } 23 }; 24 int main(){ 25 test t(0); 26 test tt = t++; 27 28 cout << tt.value() << endl; 29 cout << t.value() << endl; 30 return 0; 31 } 32 //运行结果 33 0 34 1