#include <iostream>
using namespace std;
class Per
{
private:
string name;
int age;
double *high;
double weight;
public:
//构造函数
Per(string name,int age,double high,double weight):name(name),age(age),high(new double(high)),weight(weight)
{
cout << "Per::构造函数" << endl;
}
//拷贝构造函数
Per(const Per &other):name(other.name),age(other.age),high(new double(*(other.high))),weight(other.weight)
{
cout << "Per::拷贝构造函数" << endl;
}
//析构函数
~Per()
{
delete high;
cout << "Per::析构函数" << endl;
}
};
class Stu
{
private:
double score;
Per p1;
public:
Stu(double score,string name,int age,double high,double weight):score(score),p1(name,age,high,weight)
{
cout << "Stu::构造函数" << endl;
}
Stu(const Stu &other):score(other.score),p1(other.p1)
{
cout << "Stu::拷贝构造函数" << endl;
}
~Stu()
{
cout << "Stu::析构函数" << endl;
}
};
int main()
{
Per p1("张三",18,185,80);
Per p2(p1);
cout << "++++++++++++++++++++++++++++++++++++" << endl;
Stu s1(99,"李四",20,175,60);
Stu s2(s1);
cout << "++++++++++++++++++++++++++++++++++++" << endl;
return 0;
}