功能补全
#include <iostream>
using namespace std;
class Person
{
private:
int age;
int *p;
public:
Person():p(new int(89))
{
age = 18;
}
Person(int age,int num)
{
this->age = age;
this->p=new int(num);
}
Person(Person &other)
{
this->age = other.age;
this->p=new int(*other.p);
}
Person &operator=(Person const &other)
{
if(this!=&other)
{
this->age = other.age;
this->p=new int(*other.p);
}
return *this;
}
void Show()
{
cout<< "age="<< age << endl;
cout<< "*p="<< *p << endl;
}
~Person()
{
delete p;
p=nullptr;
cout<< "空间已释放!" << endl;
cout<< "析构函数!" << endl;
}
};
int main()
{
Person P1;
Person P2(23,32);
Person P3=P2;
Person *P4=new Person;
*P4=P2;
P1.Show();
P2.Show();
P3.Show();
P4->Show();
delete P4;
return 0;
}