关于类的多重继承问题.
课本上一个类的多重继承题,代码如下,想问一下各位大佬,为什么我编完后有的成员无法输出啊?程序代码:
#include<iostream> #include<string> using namespace std; class Teacher{ public: Teacher(string nam,int ag,string s,string ad,int ph,string tit) { name = nam; ag = age; s = sex; ad = adress; ph = phone; tit =title; } void display() { cout<<"姓名:"<<name<<endl; cout<<"年龄:"<<age<<endl; cout<<"性别:"<<sex<<endl; cout<<"地址:"<<adress<<endl; cout<<"电话:"<<phone<<endl; cout<<"职称:"<<title<<endl; } private: string name; int age; string sex; string adress; int phone; string title; }; class Cadre{ public: Cadre(string nam,int ag,string s,string ad,int ph,string po) { name = nam; ag = age; s = sex; ad = adress; ph = phone; po = post; } void display() { cout<<"姓名:"<<name<<endl; cout<<"年龄:"<<age<<endl; cout<<"性别:"<<sex<<endl; cout<<"地址:"<<adress<<endl; cout<<"电话:"<<phone<<endl; cout<<"职务:"<<post<<endl; } private: string name; int age; string sex; string adress; int phone; public: string post; }; class Teacher_Cadre:public Teacher,public Cadre { public: Teacher_Cadre(string nam,int ag,string s,string ad,int ph,string tit,string po,float w): Teacher(nam,ag,s,ad,ph,tit), Cadre(nam,ag,s,ad,ph,po),wages(w){} void show() { Teacher::display(); } public: float wages; }; int main() { Teacher_Cadre TC("张三",25,"男","中国",15834564018,"副高级","院长",6000); TC.show(); cout<<endl<<"职务:"<<TC.Cadre::post<<endl; cout<<"工资:"<<TC.wages<<endl; return 0; }