加了拷贝构造的 深更半夜最后一更

 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

 

posted @ 2019-11-18 23:24  刘大侠GG_B  阅读(113)  评论(0编辑  收藏  举报