#include
using namespace std;
class Per
{
private:
string name;
int age; //年龄
float* sg; //身高
float* tz; //体重
public:
Per() {cout << "Per::无参构造函数" << endl;}
Per(string name, int age,float *sg,float *tz ):name(name),age(age),sg(new float(*sg)),tz(new float(*tz))
{
cout << "Per::有参构造函数" << endl;
}
~Per()
{
cout << "Per::析构函数" << endl;
delete sg;
delete tz;
}
Per(const Per &other):name(other.name),age(other.age),sg(new float(*(other.sg))),tz(new float(*(other.tz)))
{
cout << "Per::拷贝构造函数" << endl;
}
};
class Stu
{
private:
float cj; //成绩
Per p1;
public:
Stu() {cout << "Stu::无参构造函数" << endl;}
Stu(float cj, Per p1):cj(cj),p1(p1)
{
cout << "Stu::有参构造函数" << endl;
}
~Stu()
{
cout << "Stu::析构函数" << endl;
}
Stu(const Stu &other):cj(other.cj),p1(other.p1)
{
cout << "Stu::拷贝构造函数" << endl;
}
};
int main()
{
float a=100;
float b=100;
Per p1;
Per p2("zhangsan",18,&a,&b);
Per p3(p2);
Stu s1;
Stu s2(100,p1);
Stu s3(s1);
return 0;
}
