我在Ubuntu中使用g ++编译器时遇到了一个非常恼人的错误。
这是我的代码。
Employee.h
#ifndef Employee_h
#define Employee_h
#include<string>
using namespace std;
class Employee
{
protected:
int employeeNumber;
string firstName;
string lastName;
string address;
string telephone;
double salary;
int generateEmployeeNumber();
public:
Employee();
Employee(string fin, string lan, string add, string tel, double sal);
void setEmployeeName(string fin, string lan); //start of setters
void setEmployeeAddress(string add);
void setEmployeeTelephone(string tel);
void setEmployeeSalary(double sal);
string getEmployeeFirstName(); //start of getters
string getEmployeeLastName();
string getEmployeeAddress();
string getEmployeeTelephone();
double getEmployeeSalary();
int show();
};
#endif
Employee.cpp
#include"Employee.h"
#include<iostream>
#include<string>
using namespace std;
//start of constructors
Employee::Employee()
{
}
Employee::Employee(string fin, string lan, string add, string tel, double sal)
{
firstName = fin;
lastName = lan;
address = add;
telephone = tel;
salary = sal;
}
//end of constructors
//start of setters
void Employee::setEmployeeName(string fin, string lan)
{
cout<<"Please enter the Employee's first name: ";
cin>>fin;
cout<<"Please enter the Employee's last name: ";
cin>>lan;
firstName = fin;
lastName = lan;
}
void Employee::setEmployeeAddress(string add)
{
cout<<"Please enter the Employee's address: ";
cin>>add;
address = add;
}
void Employee::setEmployeeTelephone(string tel)
{
cout<<"Please enter the Employee's telephone number: ";
cin>>tel;
telephone = tel;
}
void Employee::setEmployeeSalary(double sal)
{
cout<<"Please enter the Employee's monthly salary: R";
cin>>sal;
salary = sal;
}
//end of setters
//start of getters
string Employee::getEmployeeFirstName()
{
return firstName;
}
string Employee::getEmployeeLastName()
{
return lastName;
}
string Employee::getEmployeeAddress()
{
return address;
}
string Employee::getEmployeeTelephone()
{
return telephone;
}
double Employee::getEmployeeSalary()
{
return salary;
}
//end of getters
这是我的错误:
Employee.cpp:31:6: error: prototype for ‘void Employee::setEmployeeName(std::string, std::string)’ does not match any in class ‘Employee’
Employee.h:22:16: error: candidate is: void Employee::setEmployeeName()
Employee.cpp:42:6: error: prototype for ‘void Employee::setEmployeeAddress(std::string)’ does not match any in class ‘Employee’
Employee.h:23:7: error: candidate is: int Employee::setEmployeeAddress(std::string)
Employee.cpp:49:6: error: prototype for ‘void Employee::setEmployeeTelephone(std::string)’ does not match any in class ‘Employee’
Employee.h:24:7: error: candidate is: int Employee::setEmployeeTelephone(std::string)
Employee.cpp:56:6: error: prototype for ‘void Employee::setEmployeeSalary(double)’ does not match any in class ‘Employee’
Employee.h:25:10: error: candidate is: double Employee::setEmployeeSalary(std::string)
有人能发现错误吗?
谢谢。
好的,我发现了问题。 在同一目录中有某种文件名Employee.h.gwh,我不知道它来自哪里,我将它删除并立即运行。 谢谢顺便说一下。
答案 0 :(得分:4)
您发布的来源是正确的,因此您必须包含另一个"Employee.h"
...您确定要编辑正确的文件吗?