#include
using namespace std;
class Person {
public:
Person()
{
cout << "无参构造函数!" << endl;
}
Person(int age)
{
mAge = age;
cout << "有参构造函数!" << endl;
}
Person(const Person &p)
{
mAge = p.mAge;
cout << "拷贝构造函数!" << endl;
}
//析构函数在释放内存之前调用
~Person() {
cout << "析构函数!" << endl;
}
public:
int mAge;
};
//以值方式返回局部对象
Person doWork2()
{
Person p1;
return p1;
}
void test03()
{
Person p=doWork2();
}
int main()
{
test03();
return 0;
}