首页 > 其他 > 详细

why the parameter in copy construction is a reference

时间:2017-02-27 13:13:37      阅读:205      评论:0      收藏:0      [点我收藏+]

if not, it will lead to an endless loop!!!

技术分享
 1 # include<iostream>
 2 using namespace std;
 3 class A
 4 {
 5 public:
 6     int var;
 7 
 8     A():var(0){}
 9 
10     A(A &a){this->var = a.var;cout << "copy\n";}
11 
12     void operator=(A b){cout << "assign\n";}
13 
14     A func(A a){return a;}
15     //A func(A &a){ return a; }
16     
17     ~A(){cout << "destroy\n";}
18 };
19 
20 int main()
21 {
22     A a, b, c;
23     b.var = 5;
24     a = b;
25     cout << "\n";
26     c = a.func(b);
27     system("pause");
28 }
View Code

 

why the parameter in copy construction is a reference

原文:http://www.cnblogs.com/resibe-3/p/6473269.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!