码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-11-19 00:44:42      阅读:63      评论:0      收藏:0      [点我收藏+]

标签:obj   div   tor   include   code   style   namespace   names   ++   

 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

 

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

标签:obj   div   tor   include   code   style   namespace   names   ++   

原文地址:https://www.cnblogs.com/DXGG-Bond/p/11886387.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!