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 }
why the parameter in copy construction is a reference
原文:http://www.cnblogs.com/resibe-3/p/6473269.html