【发布时间】:2013-01-24 19:45:17
【问题描述】:
为什么g_Fun()执行到return temp会调用拷贝构造函数?
class CExample
{
private:
int a;
public:
CExample(int b)
{
a = b;
}
CExample(const CExample& C)
{
a = C.a;
cout<<"copy"<<endl;
}
void Show ()
{
cout<<a<<endl;
}
};
CExample g_Fun()
{
CExample temp(0);
return temp;
}
int main()
{
g_Fun();
return 0;
}
【问题讨论】:
标签: c++ copy-constructor move-semantics copy-elision nrvo