作业:
#include <iostream>
using namespace std;
class Person
{
private:
int age;
int *p;
public:
//无参构造
Person():p(new int(89))
{
age=18;
cout << age <<endl;
cout << *p <<endl;
}
//有参构造
Person(int age,int num)
{
this->age=age;
this->p=new int(num);
cout <<"age:"<<age<<endl;
cout <<"point:"<<*p <<endl;
}
//拷贝构造函数
Person(Person &oth)
{
age=oth.age;
p=new int(*oth.p);
}
//拷贝赋值函数
Person &operator=(Person &pott)
{
if(this==&pott)
return *this;
age=pott.age;
p=new int (* pott.p);
return *this;
}
//析构函数
~Person()
{
delete p;
p=nullptr;
}
};
int main()
{
Person *p1=new Person(12,43);
Person *p2=new Person();
Person *p3=p1;
return 0; }