#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):age(other.age),p(new int(*(other.p)))
{
cout<<"拷贝构造"<<endl;
}
//拷贝赋值
Person &operator=(Person &other)
{
age=other.age;
*p=*(other.p);
cout<<"拷贝赋值"<<endl;
return *this;
}
void show()
{
cout << "age = " << age << endl;
cout << "p = " << *p << endl;
cout<< p<<endl;
}
//析构
~Person()
{
delete p;
cout<<"析构"<<endl;
}
};
int main()
{
int *num=new int(100);
Person p1(10,*num);
p1.show();
Person p2=p1;
p2.show();
Person p3;
p3=p2;
p3.show();
return 0;
}