设计一个Per类,类中包含私有成员:姓名、年龄、指针成员身高、体重,
再设计一个Stu类,类中包含私有成员:成绩、Per类对象p1,设计这两个类的构造函数、析构函数和拷贝构造函数。
#include <iostream>
using namespace std;
/*
设计一个Per类,类中包含私有成员:姓名、年龄、指针成员身高、体重,
再设计一个Stu类,类中包含私有成员:成绩、Per类对象p1,设计这两个类的构造函数、析构函数和拷贝构造函数。
*/
class Per{
string name;
int age;
float height;
float weight;
public:
Per(string name,int age,float height,float weight):name(name),age(age),height(height),weight(weight){cout << "Per constructor 01" << endl;}
~Per(){cout << "Per disconstructor" << endl;}
Per(const Per &p):name(p.name),age(p.age),height(p.height),weight(p.weight){cout << "Per constructor 02" << endl;}
};
class Stu{
float score;
Per &p1;
public:
Stu(float s,Per &p):score(s),p1(p){cout << "Stu constructor 01" << endl;};
~Stu(){cout << "Stu disconstructor" << endl;};
Stu(const Stu &s):score(s.score),p1(s.p1){cout << "Stu constructor 02" << endl;};
};
int main()
{
Per p("zhang meili",20,160.5,45.7);
Stu s(93,p);
return 0;
}