#include<iostream>
#include<string>
using namespace std;
class Teacher
{
public:
Teacher( string name, string sex, string phone, string add,string title, int year) :name(name), sex(sex), phone(phone), add(add), title(title), year(year){}
void show()
{
cout << "name" << name << endl;
cout << "sex" << sex << endl;
cout << "year" << year << endl;
cout << "phone" << phone << endl;
cout << "add" << add << endl;
cout << "title" << title << endl;
}
protected:
string name, sex, phone, add, title; int year;
};
class cadre
{
public:
cadre(string post, string name, string sex, string phone, string add, int year) :name(name), sex(sex), phone(phone), add(add), post(post), year(year) {}
void show()
{
cout << "name" << name << endl;
cout << "sex" << sex << endl;
cout << "year" << year << endl;
cout << "phone" << phone << endl;
cout << "add" << add << endl;
cout << "post" << post << endl;
}
protected:
string name, phone, sex, add, post; int year;
};
class Teacher_cadre :public Teacher, public cadre
{
public:
Teacher_cadre( string name, string sex, string phone, string add, string title, int year, string post, float wage)
:Teacher(name, sex, phone, add, title ,year), cadre(name, sex, phone, add, post ,year ), wage(wage) {}
void dispaly()
{
Teacher::show();
cout << post << post << endl;
cout << wage << wage << endl;
}
private:
float wage;
};
int main()
{
Teacher_cadre obj("张三","男", 35,"1234561111", "重庆永川", "教授", "院长", 8000);
obj.Teacher::show();
obj.dispaly();
return 0;
}
你这是定义对象时参数列表不对应,你定义的对象后面的括号里第三个是int 型年龄,但是Teacher_cadre类构造函数你把对应的写到了倒数第三个,传入的参数列表要和定义的对应,不然就会强制类型转换,导致程序出错。