后++,赋值操作符重载,构造函数调用才会产生对象
#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 int value(){ 11 return mvalue; 12 } 13 test& operator++(){ 14 ++mvalue; 15 return *this; 16 } 17 //后++ 18 test operator++(int){ 19 cout << "test operator++" << endl; 20 test ret(mvalue); 21 mvalue++; 22 cout << "mvalue=" << mvalue << endl; 23 return ret; 24 } 25 }; 26 int main(){ 27 test t(0); //test(int i)=0 28 test tt = t++; //test operator ++; test(int i)=0 29 cout << tt.value() << endl; 30 cout << t.value() << endl; 31 return 0; 32 //运行结果 33 test(int i)=0 34 test operator++ 35 test(int i)=0 36 0 37 1