猿问

编译的时候没有错,运行时错

#include <iostream>

#include <string>

using namespace std;


class Teacher

{

public:

Teacher();

Teacher(string x_name,string x_sex,string x_addr,int x_age,int x_tell,int x_title);

~Teacher()

{

cout<<"Teacher destructor!"<<endl;

}

void T_display()

{

cout<<"Name is :"<<s_name<<endl<<"Age is: "<<s_age<<endl<<"Sex is: "<<s_sex<<endl<<"Address is: "<<s_addr<<endl<<"Telephone is: "<<s_tel<<endl<<"Title is: "<<s_title<<endl;

}

protected:

string s_name;

string s_sex;

string s_addr;

int s_age;

int s_tel;

int s_title;


};

Teacher::Teacher(string x_name,string x_sex,string x_addr,int x_age,int x_tel,int x_title)

{

s_name=x_name;

s_sex=x_sex;

s_addr=x_addr;

s_age=x_age;

s_tel=x_tel;

s_title=x_title;


}


class Cadre

{

public:

Cadre(string x_name,string x_sex,string x_addr,int x_age,int x_tell,int x_title);

~Cadre()

{

cout<<"Cadre destructor!"<<endl;

}

void C_display()

{

cout<<"Name is :"<<s_name<<endl<<"Age is: "<<s_age<<endl<<"Sex is: "<<s_sex<<endl<<"Address is: "<<s_addr<<endl<<"Telephone is: "<<s_tel<<"Post is"<<s_post<<endl;

}

protected:

string s_name;

int s_age;

string s_sex;

string s_addr;

int s_tel;

int s_post;


};

Cadre::Cadre(string h_name,string h_sex,string h_addr,int h_age,int h_tel,int h_post)

{

s_name=h_name;

s_sex=h_sex;

s_addr=h_addr;

s_age=h_age;

s_tel=h_tel;

s_post=h_post;


}


class Teacher_Cadre:public Teacher,public Cadre

{

public:

Teacher_Cadre();

void show();


private:

int wages;

};


void Teacher_Cadre::show()

{

Teacher::T_display;


}

//void Teacher_Cadre(){}


int main()

{

Teacher t("sd","dad","sdasd",45,4,8);

Cadre c("fsd","asdf","sdf",45,8,54);

Teacher_Cadre s;

s.show();



system("pause");

return 0;

}


dw123456
浏览 1484回答 2
2回答

guozhchun

不知你用的是什么编译器,反正这代码我编译不过。解释一下原因:Teacher_Cadre这个类没有定义无参构造函数(代码中那个是声明,不是定义)
随时随地看视频慕课网APP
我要回答