#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
class Person
{
public:
int* height;
int* age;
public:
Person(int age, int height)
{
this->age = new int;
this->height = new int;
*this->age = age;
*this->height = height;
cout << "调用构造函数" << endl;
}
//浅拷贝
/*Person(const Person& p)
{
age = p.age;
height = p.height;
}*/
//深拷贝
Person(const Person& p)
{
age = new int;
height = new int;
*age = *p.age;
*height = *p.height;
}
~Person()
{
delete height;
delete age;
cout << "调用析构函数" << endl;
}
};
void test01()
{
Person p1(160, 12);
cout << "p1.age = " << *p1.age << " p1.height = " << *p1.height << endl;
Person p2 = p1;
cout << "p2.age = " << *p1.age << " p2.height = " << *p1.height << endl;
}
int main()
{
test01();
return 0;
}