C++默认拷贝构造
class Person
{
public:
Person()
{
std::cout << "Person()构造" << std::endl;
}
~Person()
{
std::cout << "~Person()析构" << std::endl;
}
int age_get()
{
return m_age;
}
void age_set(int age)
{
m_age = age;
}
private:
int m_age;
};
int main()
{
Person p1;
p1.age_set(12);
Person p2 = p1;
std::cout << p2.age_get() << std::endl;
Person p3(p1);
std::cout << p3.age_get() << std::endl;
return 0;
}
$ ./a.out
Person()构造
12
12
~Person()析构
~Person()析构
~Person()析构