关于复制构造函数的问题
下面这段程序的运行结果是fun2()...
copy constructor
copy constructor
after fun2()...
为什么会有两个“copy constructor”呢?
程序如下:
#include<iostream>
using namespace std;
class Test
{
public:
int a;
Test(int x)
{
a=x;
}
Test(Test &test)
{
cout<<"copy constructor"<<endl;
a=test.a;
}
};
Test fun2()
{
Test t(1);
cout<<"fun2()..."<<endl;
return t;
}
int main()
{
Test t3=fun2();
cout<<"before fun2()..."<<endl;
return 0;
}