为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C++
dw123456 2016-04-24 18:34:29
#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;}
查看完整描述

2 回答

已采纳
?
guozhchun

TA贡献103条经验 获得超76个赞

不知你用的是什么编译器,反正这代码我编译不过。解释一下原因:Teacher_Cadre这个类没有定义无参构造函数(代码中那个是声明,不是定义)

查看完整回答
反对 回复 2016-04-24
  • dw123456
    dw123456
    VC6.0 那应该怎么写...已经要疯了
  • guozhchun
    guozhchun
    你代码中有写其他类的有参构造函数的定义,写个Teacher_Cadre类的无参构造函数的定义应该不难吧
  • dw123456
    dw123456
    已经搞定 谢谢
  • 2 回答
  • 0 关注
  • 1444 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信