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

test tt=0 <=>test(0)

时间:2019-11-18 22:17:57      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:code   operator   ++   return   div   nbsp   结果   style   test   

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

 

test tt=0 <=>test(0)

标签:code   operator   ++   return   div   nbsp   结果   style   test   

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

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