**#include <iostream>
#include <string>
using namespace std;
class Student{
public:
Student(int n,string nam)
{
num=n;
name=nam;
}
void display()
{
cout<<"num:"<<num<<endl<<"name:"<<name<<endl;
}
protected:
int num;
string name;
};
class Student1:public Student
{
public:
Student1(int n,string nam,int a):Student(n,nam)//注意不要只需写出其上一层派生类(即其直接基类)的构造函数
{
age=a;
}
void show()
{
display();
cout<<"age:"<<age<<endl;
}
private:
int age;
};
class Student2:public Student1{
public:
//下面是间接派生类构造函数
Student2(int n,string nam,int a,int s):Student1(n,nam,a)
{
score=s;
}
void show_all(){
show();
cout<<"score:"<<score<<endl;
}
private:
int score;
};
int main() {
Student2 stud(10010, "Li", 17, 89);
stud.show();
return 0;
}
**
**/home/andrew/文档/Clion/untitled5/cmake-build-debug/untitled5
num:10010
name:Li
age:17
Process finished with exit code 0
**