Can someone please explain to me why I'm getting the following compiler errors when I compile this code. I've been reading a C++ book, and it tells me that I should always use const at the end of the definition (int function() const which apparently says that the function I'm using it with won't be changing the values of variables, and that using const is a good way to help ensure bug-free programs.
These are the errors:
Code:
Error: int Employee::getAge(void)' : overloaded member function not found in 'Employee'
Error: int Employee::getYearOfService(void)' : overloaded member function not found in 'Employee'
Error: int Employee::Salary(void)' : overloaded member function not found in 'Employee'
And the code here:
Code:
#include <iostream>
using namespace std;
class Employee {
public:
Employee();
~Employee();
int getAge() const;
void setAge(int Age);
int getYearOfService() const;
void setYearOfService(int YearOfService);
int getSalary() const;
void setSalary(int Salary);
private:
int itsAge;
int itsYearOfService;
int itsSalary;
};
Employee::Employee(){
itsAge = 0;
itsYearOfService = 0;
itsSalary = 0;
}
Employee::~Employee(){
}
int Employee::getAge(){
return this->itsAge;
}
void Employee::setAge(int Age){
this->itsAge = Age;
}
int Employee::getYearOfService(){
return this->itsYearOfService;
}
void Employee::setYearOfService(int YearOfService){
this->itsYearOfService = YearOfService;
}
int Employee::getSalary(){
return this->itsSalary;
}
void Employee::setSalary(int Salary){
this->itsSalary = Salary;
}
int main(){
Employee Employee1;
Employee Employee2;
Employee1.setAge(21);
Employee1.setSalary(26000);
Employee1.setYearOfService(6);
Employee2.setAge(33);
Employee2.setSalary(39000);
Employee2.setYearOfService(13);
cout << "Employee 1 - Age: " << Employee1.getAge() << endl;
cout << "Employee 1 - Salary: " << Employee1.getSalary() << endl;
cout << "Employee 1 - Years Served: " << Employee1.getYearOfService() << endl << endl;
cout << "Employee 2 - Age: " << Employee2.getAge() << endl;
cout << "Employee 2 - Salary: " << Employee2.getSalary() << endl;
cout << "Employee 2 - Years Served: " << Employee2.getYearOfService() << endl;
cin.get();
}
Thanks a lot!