考虑一下:
#include <iostream>
struct A{
A(){
std::cout << "Create empty A" << std::endl;
}
A(const A& a){
// Why is this never called??
std::cout << "Never called" << std::endl;
}
};
A genA() {
A a;
return a;
}
int main(int argc, const char *argv[])
{
A a(genA()); // Expected to call copy constructor
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么没有调用复制构造函数?
如果我想确保每次复制A时屏幕上都印有"从不打电话",我该怎么办?
| 归档时间: |
|
| 查看次数: |
162 次 |
| 最近记录: |