#include<iostream>
using namespace std;
#include<string>
class Person
{
public:
Person(int age)
{
m_Age = new int(age);
}
~Person()
{
if(m_Age != NULL)
{
delete m_Age;
m_Age = NULL;
}
}
//赋值运算符重载
Person& operator=(Person &p)
{
if(m_Age != NULL)
{
delete m_Age;
m_Age =NULL;
}
m_Age = new int(*p.m_Age);
return *this;
}
int *m_Age;
};
void test()
{
Person p1(12);
Person p2(20);
Person p3(50);
p3=p2=p1;
cout<<"p1.m_Age="<<*p1.m_Age<<endl;
cout<<"p2.m_Age="<<*p2.m_Age<<endl;
cout<<"p3.m_Age="<<*p3.m_Age<<endl;
}
int main()
{
test();
system("pause");
return 0;
}