思维导图
#include <iostream>using namespace std;class Person{
private:string name;int age;int *heigh;int *weight;public:Person(){cout << "person::空参构造" << endl;}Person(string name, int age, int *heigh, int *weight):name(name), age(age), heigh(heigh), weight(weight){cout << "person::含参构造" << endl;}~Person(){delete heigh;delete weight;cout << "person::析构函数" << endl;}
};class Student{
private:Person p;double score;public:Student(){cout << "student::空参构造" << endl;}Student(string name, int age, int *heigh, int *weight, double score):p(name, age, heigh, weight), score(score){cout << "student::含参构造" << endl;}~Student(){cout << "student::析构函数" << endl;}
};int main()
{int heigh = 180;int weight = 70;int *h = &heigh;int *w = &weight;Student s1();Student s2("zhangsan", 23, h, w, 99.9);return 0;
}