1.
2.
#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&m)
{
age=m.age;
p=new int;
*p=*(m.p);
cout<<"person的拷贝构造函数"<<endl;
}
Person &operator=(Person &other)
{
age=other.age;
*p=*(other.p);
cout<<"person的拷贝赋值函数"<<endl;
}
~Person()
{
delete p;
p=nullptr;
cout<<"person的析构函数"<<endl;
}
};
int main()
{
Person s1;
Person s2(22,99);
Person s3=s2;
Person s4;
s4=s1;
return 0;
}