#include
using namespace std;
class Person
{
public:
Person()
{
cout << "Person 默认构造函数" << endl;
}
Person(int age) //有参构造
{
cout << "Person 有参构造函数" << endl;
m_age = age;
}
Person(const Person &a) //拷贝构造
{
cout << "Person 拷贝构造函数" << endl;
m_age = a.m_age;
}
~Person()
{
cout << "Person 析构函数调用" << endl;
}
int m_age;
};
Person doWork()
{
Person p1;
return p1;
}
void test03()
{
Person p = doWork();
}
int main()
{
test03();
system("pause");
return 0;
}
请问一下,我这边调用**test03()函数,按道理doWork()**会按值返回p1这个局部对象,return返回值应该也是创建一个副本吧?但最后的运行结果并没有拷贝构造函数的生成,这是为什么?