#include <iostream>
using namespace std;
class Per
{
private:
string name;
int age;
double *high;
double *weight;
public:
Per(){}
Per(string name,int age,double high,double weight):name(name),age(age),high(new double(high)),weight(new double(weight))
{
cout << "Per::有参构造函数" <<endl;
}
~Per()
{
delete high;
delete weight;
cout << "Per::析构函数" <<endl;
}
Per(const Per &other):name(other.name),age(other.age),high(new double(*(other.high))),weight(new double(*(other.weight)))
{
cout << "Per::拷贝构造函数" <<endl;
}
};
class Stu
{
private:
double score;
Per p1;
public:
//没有指针 指向堆区 不需要析构函数 拷贝使用默认的浅拷贝即可 Per的拷贝转至Per类中拷贝
Stu()
{
cout << "Stu::无参构造函数" << endl;
}
Stu(double score,string name,int age,double high,double weight):score(score),p1(name,age,high,weight)
{
cout << "Stu::有参构造函数" <<endl;
}
~Stu()
{
cout << "Stu::析构函数" << endl;
}
Stu(const Stu &other):score(other.score),p1(other.p1)
{
cout << "Stu::拷贝函数" << endl;
}
};
int main()
{
Stu s1(99,"张三",19,182,15);
Stu s2(s1);
return 0;
}