Ice*_*man 3 c++ copy-constructor
Line Line::operator =(Line ln) {
cout << "Assignment operator\n";
Line temp;
temp.ptr = new int;
*temp.ptr = *(ln.ptr);
return temp;
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,执行以下语句时不会调用复制构造函数:
return temp;
Run Code Online (Sandbox Code Playgroud)
由于返回是按值,为什么不调用复制构造函数?
谢谢
| 归档时间: |
|
| 查看次数: |
164 次 |
| 最近记录: |