我写的一个程序,但是编译有错误,不太理解,请大侠进来帮帮忙。谢谢谢谢啦。

unique_1 2012-04-30 09:02:56
#include<iostream>
#include<string>
using namespace std;
class Person
{
public:
Person(string n,string s,int a);
void show() ;
private:
string name;
string sex;
int age;
};
Person::Person(string n,string s,int a)
{
name=n;
sex=s;
age=a;
}
void Person::show()
{
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"age"<<age<<endl;
}
class Teacher:public Person
{
public:
Teacher(string n,string s,int a,string j,string c);
void show() ;
private:
string job;
string course;
}
Teacher::Teacher(string n,string s,int a,string j,string c):Person(n,s,a)
{
job=j;
course=c;
}
void Teacher::show()
{
Person::show();
cout<<"job:"<<job<<endl;
cout<<"course:"<<course<<endl;
}
class Student:public Person
{
public:
Student(string n,string s,int a,int no,string sub);
void show() ;

private:
int number;
string subject;
};
Student::Student(string n,string s,int a,int no,string sub):Person(n,s,a)
{
number=no;
subject=sub;
}
void Student::show()
{
Person::show();
cout<<"number:"<<number<<endl;
cout<<"subject:"<<subject<<endl;

}
class Gradstudent:public Student
{
public:
Gradstudent(string n,string s,int a,int no,string sub,string te ) ;
void show() ;
private:
string daoshi;
};
Gradstudent::Gradstudent(string n,string s,int a,int no,string sub,string te):Student(n,s,a,no,sub)
{
daoshi=te;
}
void Gradstudent::show()
{ Student::show();
cout<<"daoshi:"<<daoshi<<endl;

}
int main()
{
Student A("tom","girl",20,12,"computer");
Teacher B("xiao","boy",40,"professor","math");
A. show();
B. show();
return 0;
}


请大家帮我改改这个程序的错误,编译错误是:
d:\c程序\sy5_3\sy5_3.cpp(35) : error C2533: 'Teacher::Teacher' : constructors not allowed a return type
d:\c程序\sy5_3\sy5_3.cpp(88) : error C2264: 'Teacher::Teacher' : error in function definition or declaration; function not called
...全文
108 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
evencoming 2012-04-30
  • 打赏
  • 举报
回复
Teacher 构造函数不能有返回值
「已注销」 2012-04-30
  • 打赏
  • 举报
回复
Teacher类后面少了个 ;
unique_1 2012-04-30
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
42 行漏了一个分号,加上后就可以了
定义class最后记得有分号;
[/Quote]哦哦。这么没营养的错误,愧疚啦。谢谢啦!
lionmanong 2012-04-30
  • 打赏
  • 举报
回复
42 行漏了一个分号,加上后就可以了
定义class最后记得有分号;
lionmanong 2012-04-30
  • 打赏
  • 举报
回复
}; 这里漏了一个分号;

64,662

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧