I'm having problem getting some separate compilation done. It's simple, but I can't figure out this error.
I'm getting these exceptions:
> 36 C:\Cpp\P6\employee.cpp expected `)' before ',' token 36
> C:\Cpp\P6\employee.cpp expectedinit-declarator before ')' token 36
> C:\Cpp\P6\employee.cpp expected `,' or `;' before ')' token 42
> C:\Cpp\P6\employee.cpp expected `)' before ',' token 42
> C:\Cpp\P6\employee.cpp expected init-declarator before ')' token 42
> 开发者_运维知识库C:\Cpp\P6\employee.cpp expected `,' or `;' before ')' token
for this code:
/*line 36*/ Employee::Employee(n, id) { //constructor for name and ID
setName(n);
setID(id);
};
/*line 42*/ Employee::Employee(id, d, p, n) {//constructor for all member variables
setID(id);
setDept(d);
setPos(p);
setName(n);
};
the header file looks like(they're public):
Employee::Employee();
Employee::Employee(std::string, int);
Employee::Employee(int, std::string, std::string, std::string);
Any help as to what those errors mean or how I can fix them?
You always have to have a type preceding variable name. You have it in declaration but not in definition. Something like the following should fix it:
Employee::Employee(std::string n, int id) { //constructor for name and ID
setName(n);
setID(id);
};
Same goes for the second Employee
constructor definition.
Also, it is better to pass std::string
by constant reference rather than by value. And... you avatar is rotated 45 degrees left.
精彩评论