淺拷貝:簡單的賦值拷貝操作
深拷貝:在堆區(qū)重新申請空間释液,進行拷貝操作
class Person {
public:
int m_age;
int *m_height;
// 無參(默認)構(gòu)造函數(shù)
Person(){
cout <<"無參構(gòu)造函數(shù)" << endl;
}
// 有參構(gòu)造函數(shù)
Person(int age, int height){
cout << "有參構(gòu)造函數(shù)!" endl;
m_height = new int(height);
m_age = age;
}
~Person()
{
// 析構(gòu)代碼,將堆區(qū)開辟數(shù)據(jù)做釋放操作
if (m_height != Null)
{
delete m_height;
//為了防止出現(xiàn)野指針炫隶,我們將其置空
m_height = Null;
}
}
}