C++ 错误:在';int';代码中有很多类似的错误
附言:我是初学者。 我尝试的完整代码如下所示: 错误出现在第30、50、63、74和82行,如: 第30行:“int”之前的预期主表达式;“char”之前应为主表达式; 第50行:“int”之前的预期主表达式;“char”之前应为主表达式; 第63行:“int”之前的预期主表达式;“char”之前应为主表达式; 第74行:“int”之前的预期主表达式;“char”之前应为主表达式;“int”之前应为主表达式; 第82行:“int”之前的预期主表达式;“char”之前应为主表达式;“int”之前应为主表达式C++ 错误:在';int';代码中有很多类似的错误,c++,C++,附言:我是初学者。 我尝试的完整代码如下所示: 错误出现在第30、50、63、74和82行,如: 第30行:“int”之前的预期主表达式;“char”之前应为主表达式; 第50行:“int”之前的预期主表达式;“char”之前应为主表达式; 第63行:“int”之前的预期主表达式;“char”之前应为主表达式; 第74行:“int”之前的预期主表达式;“char”之前应为主表达式;“int”之前应为主表达式; 第82行:“int”之前的预期主表达式;“char”之前应为主表达式;“int”之前应
#include <iostream>
#include <math.h>
#include <cstring>
using namespace std;
class staff{
protected:
int code;
char *name;
public:
staff(){}
staff(int code1,char *name1){
code=code1;
int length;
length=strlen(name1);
name=new char[length+1];
strcpy(name,name1);
}
void display(){
cout<<"Staff code is: "<<code<<"\n";
cout<<"Name is: "<<name<<"\n";
}
};
class teacher:public staff{
protected:
char *subject;
char *publication;
public:
teacher(){}
teacher(int code1,char *name1,char *sub1,char *pub1):
staff(int code1,char *name1){ //line 30
int len1,len2;
len1=strlen(sub1);
len2=strlen(pub1);
subject=new char[len1+1];
publication=new char[len2+1];
strcpy(subject,sub1);
strcpy(publication,pub1);
}
void display_t(){
cout<<"Subject is: "<<subject<<"\n";
cout<<"Publication is: "<<publication<<"\n";
}
};
class officer:public staff{
protected:
char grade;
public:
officer(){}
officer(int code1,char *name1,char grd1):
staff(int code1,char *name1){ //line 50
grade=grd1;
}
void display_o(){
cout<<"Grade is: "<<grade;
}
};
class typist:public staff{
protected:
int speed;
public:
typist(){}
typist(int code1,char *name1,int spd):
staff(int code1,char *name1){ //line 63
speed=spd;
}
void display_typ(){
cout<<"Speed is: "<<speed<<"\n";
}
};
class regular:public typist{
public:
regular(){}
regular(int code1,char *name1,int spd):
typist(int code1,char *name1,int spd){} //line 74
};
class casual:public typist{
protected:
float dailywage;
public:
casual(){}
casual(float wage,int code1,char *name1,int spd):
typist(int code1,char *name1,int spd){ //line 82
dailywage=wage;
}
void display_c(){
cout<<"Daily wage of casual typists are: "<<dailywage<<"\n";
}
};
int main()
{
casual c1;
c1=casual(2100.05,002,"Ganesh",50);
c1.display();
//c1.display_t();
c1.display_typ();
//c1.display_o();
c1.display_c();
return 0;
}
#包括
#包括
#包括
使用名称空间std;
班主任{
受保护的:
int代码;
字符*名称;
公众:
staff(){}
职员(内部代码1,字符*name1){
代码=代码1;
整数长度;
长度=strlen(名称1);
名称=新字符[长度+1];
strcpy(名称,名称1);
}
无效显示(){
cout在这一行:
teacher(int code1,char *name1,char *sub1,char *pub1):
staff(int code1,char *name1) {
调用基类构造函数时使用了错误的语法。只需传递变量,而不需要传递类型
以下是如何正确书写:
teacher(int code1,char *name1,char *sub1,char *pub1):
staff(code1, name1) {
所有其他错误都是由相同的错误引起的,因此需要对所有派生类的构造函数执行此操作。在这一行:
teacher(int code1,char *name1,char *sub1,char *pub1):
staff(int code1,char *name1) {
调用基类构造函数时使用了错误的语法。只需传递变量,而不需要传递类型
以下是如何正确书写:
teacher(int code1,char *name1,char *sub1,char *pub1):
staff(code1, name1) {
所有其他错误都是由相同的错误引起的,因此您需要对所有派生类的构造函数执行此操作。我们看不到行号。请将错误消息作为注释添加到有错误的行旁边。将行号作为注释添加到代码的右侧。谢谢。谢谢,这样更好。谢谢@cigien,I这是很好的。当你可以的时候考虑一下答案。我们看不到行数。请把错误信息添加到有错误的行旁边的注释中。把行号作为右边的注释添加到代码中。谢谢。谢谢。当你可以的时候。