#include<iostream>
#include<string>
using namespace std;
class Person//定义一个基类
{
protected:
string name;
int age;
char sex;
string address;
long telephone;
public:
Person(const string a, int b, char s, const string add, long tel);
};
Person::Person(const string a, int b, char s, const string add, long tel) :name(a), age(b), sex(s), address(add), telephone(tel) {}
class Teacher :virtual public Person//教师类
{
public:
string title;//职称
Teacher(const string a, int b, char s, const string add, long tel, const string tit);
void display();
};
Teacher::Teacher(const string a, int b, char s, const string add, long tel, const string tit) :Person(a, b, s, add, tel), title(tit) {}
void Teacher::display()
{
cout << "姓名为:" << name << endl;
cout << "年龄为:" << age << endl;
cout << "性别为:" << sex << endl;
cout << "地址为:" << address << endl;
cout << "电话为:" << telephone << endl;
cout << "职称为:" << title << endl;
}
class Cadre :virtual public Person//干部类
{
public:
string post;//职务
Cadre(const string a, int b, char s,const string add,const long tel, string post);
void display();
};
Cadre::Cadre(const string a, int b, char s, const string add, long tel, const string post) :Person(a, b, s, add, tel), post(post) {}
void Cadre::display()
{
cout << "姓名为:" << name << endl;
cout << "年龄为:" << age << endl;
cout << "性别为:" << sex << endl;
cout << "地址为:" << address << endl;
cout << "电话为:" << telephone << endl;
cout << "职务为:" << post << endl;
}
class Teacher_Cadre :public Teacher, public Cadre//教师兼干部类
{
public:
int wages;//工资
Teacher_Cadre(const string a, int b, char s, const string add, long tel, const string tit, const string post, int w);
void show();
};
Teacher_Cadre::Teacher_Cadre(const string a, int b, char s, const string add, long tel, const string tit, const string post, int w) :Person(a, b, s, add, tel), Teacher(a, b, s, add, tel, tit), Cadre(a, b, s, add, tel, post), wages(w) {}
void Teacher_Cadre::show()
{
Teacher::display();
cout << "工资为:" << wages << endl;
}
int main()
{
Teacher_Cadre m("李华", 36, "男", "湖北大学教工处", 123456, "英语老师", "教导主任", 6000);
m.show();
system("pause");
return 0;
}
代码如上
构造函数第三个参数是char s,你传递的是"男“,不匹配。"男”是中文,占两个字节,你需要把性别也定义成字符数组才行
您的问题已经有小伙伴解答了,请点击【采纳】按钮,采纳帮您提供解决思路的答案,给回答的人一些鼓励哦~~
ps:开通问答VIP,享受5次/月 有问必答服务,了解详情↓↓↓
【电脑端】戳>>> https://vip.csdn.net/askvip?utm_source=1146287632
【APP 】 戳>>> https://mall.csdn.net/item/52471?utm_source=1146287632