//// Created by bell on 2021年7月2日.//#include<iostream>using namespace std;//基类Peopleclass People{protected:char *m_name;int m_age;public:People(char*, int);~People(){cout<<"destructor of pepele"<<endl;};};People::People(char *name, int age): m_name(name), m_age(age){cout<<"constructor of people"<<endl;}//派生类Studentclass Student: public People{private:float m_score;public:Student(char *name, int age, float score): People(name, age), m_score(score){cout<<"constructor of student"<<endl; }~Student(){cout<<"destructor of student"<<endl;}void display();};//People(name, age)就是调用基类的构造函数//Student::Student(char *name, int age, float score): People(name, age), m_score(score){cout<<"constructor of student"<<endl; }void Student::display(){cout<<m_name<<"的年龄是"<<m_age<<",成绩是"<<m_score<<"。"<<endl;}class GoodStudent: public People,public Student{public:GoodStudent();};int main(){Student stu("小明", 16, 90.5);stu.display();return 0;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。