Why can't I use inline functions with my setter method in c++. Here is the code:
Main.cpp
#include <iostream>
#include "Employee.h"
using namespace std;
int main()
{
Employee h;
h.setAge(30);
h.setSalary(70000);
h.setyearsOfService(5);
h.printAllInfo();
return 0;
}
Employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
class Employee
{
public:
inline int getAge();
int setAge(int n);
inline int getyearsOfService();
int setyearsOfService(int n);
inline int getSalary();
inline int setSalary(int n);
void printAllInfo();
private:
unsigned int age;
unsigned int yearsOfService;
unsigned int Salary;
};
#endif // EMPLOYEE_H
Employee.cpp
#include "Employee.h"
#include<iostream>
int Employee::getAge()
{
return age;
}
int Employee::setAge(int n)
{
age = n;
return age;
}
int Employee::getSalary()
{
return Salary;
}
int Employee::setSalary(int n)
{
Salary = n;
return Salary;
}
int Employee::setyearsOfService(int n)
{
yearsOfService = n;
return yearsOfService;
}
int Employee::getyearsOfService()
{
return yearsOfService;
}
void Employee::printAllInfo()
{
using std::cout;
using std::endl;
cout << "The employee is " << getAge() << " year old and he has worked for " << getyearsOfService() << " years and his/her salary is " << getSalary() << " smakroos" << endl;
}
Here is the build log I get when I try to compile:
Day6Programming/main.cpp:10: undefined reference to `Employee::setSalary(int)'
Why am I getting this error?