浅拷贝:简单的赋值拷贝操作
深拷贝:在堆区重新申请空间,进行拷贝操作
class Person {
public:
int m_age;
int *m_height;
// 无参(默认)构造函数
Person(){
cout <<"无参构造函数" << endl;
}
// 有参构造函数
Person(int age, int height){
cout << "有参构造函数!" endl;
m_height = new int(height);
m_age = age;
}
~Person()
{
// 析构代码,将堆区开辟数据做释放操作
if (m_height != Null)
{
delete m_height;
//为了防止出现野指针,我们将其置空
m_height = Null;
}
}
}