c++小问? 急!!急!!!

来源:百度知道 编辑:UC知道 时间:2024/09/24 01:51:54
void Student::Student(string No,string Name)
{
stu_No=No;
stu_Name=Name;
}
错误显示:constructors not allowed a return type
哪位可以帮帮这是什么问题,什么改正!
class Student //基类Student类
{
protected:
string stu_No;
string stu_Name;
public:
Student();
Student(string No,string Name);
void show_infor();
};
class English_stu: public Student //English_stu类
{
protected:
string stu_depart;
double stu_score;
public:
English_stu();
English_stu(string dep,double sco);
void show_infor();
};

Student::Student(string No,string Name)
{
stu_No=No;
stu_Name=Name;
}
void Student::show_infor()
{
cout<<"该学生学号为:"<<stu_No<<endl;
cout<<"该学生姓名为:"<<stu_Name<<endl;
}

你问题补充前的回答:
void Student::Student(string No,string Name)
{
stu_No=No;
stu_Name=Name;
}
错误显示:constructors not allowed a return type

看你的错误信息应该是没有返回类型吧,

你在后面加个return;试试看!
void Student::Student(string No,string Name)//这里是void,后面要有个
{ //return;
stu_No=No;
stu_Name=Name;
return;
} //上面的回答是错的;
你问题补充之后的回答:
看了你的问题补充才知道,不是要加个return;因为构造函数不能有任何返回类型的所以去掉void;

在类定义或者申明时,结束的地方忘了加个;(分号)

构造函数不允许指定返回类型。
Student::Student(string No,string Name)
{
stu_No=No;
stu_Name=Name;
}

构造函数是不能有任何返回类型的,无返回类型是指什么都不用写,不是void ,将void去掉就ok了。。

void Student::Student(string No,string Name)
=>

Student::Student(string No,string Name)