求一个多层派生时的构造函数程序问题?
#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;
cout<<"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;
}
protected:
int age;
};
class Student2:public Student1
{
Student2(int n,string nam,int a,int s):Student1(n,nam,a),score(s){}
void show_all()
{
show();
cout<<"score:"<<score<<endl;
}
protected:
int score;
};
void main()
{
Student2 stud(10010,"Zhangcan",17,89);
stud.show_all();
}
帮忙各位高手给看看这个程序!谢谢!