关于多重继承的一道程序
题目:定义Teacher类和Carde类,采用多重继承派生出Teacher_Carde类,要求在派生类的成员函数show中调用Teacher类中的display函数,输出信息,但是执行的时候display中的信息无法输出,求解答
#include <iostream>
#include <string>
using namespace std;
class Teacher //Teacher类
{
public:
void display(); //输出函数
Teacher(string n,int a,char s,string t);
protected:
string name; //姓名
int age; //年龄
char sex; //性别
string title; //职称
};
void Teacher::display()
{
cout<<"name:"<<endl;
cout<<"age:"<<endl;
cout<<"sex:"<<endl;
cout<<"title:"<<endl;
}
Teacher::Teacher(string n,int a,char s,string t)
{
name=n;
age=a;
sex=s;
title=t;
}
class Cadre //Cadre 类
{
public:
Cadre(string n,int a,char s,string p);
protected:
string name;
int age;
char sex;
string post;
};
Cadre::Cadre(string n,int a,char s,string p)
{
name=n;
age=a;
sex=s;
post=p;
}
class Teacher_Cadre:public Teacher,public Cadre //派生类
{
public:
void show();
Teacher_Cadre(string n,int a,char s,string t,string p,float w):Teacher(n,a,s,t),Cadre(n,a,s,p)
{
wages=w;
}
private:
float wages;
};
void Teacher_Cadre::show()
{
display();
cout<<"post:"<<post1<<endl;
cout<<"wage:"<<wages<<endl;
}
int main()
{
Teacher_Cadre t1("sun",20,'m',"teacher","jiaoshou",1234.5);
t1.show();
return 0;
}