I'm trying to print the employee count after each created object but I'm getting an error like this: undefined reference to `Employee::numberofEmployees'. How can I solve this little problem? Any ideas? Btw I'm using a local class.
the purpose of the numberofEmployees variable is to store the information on the number of employee objects created/instantiated so far.
#include <iostream>
#include <string>
using namespace std;
class Employee{
public:
string name;
string surname;
int year;
double salary;
static int numberofEmployees;
Employee(int yil,string isim,string soyisim): year(yil),name(isim),surname(soyisim){
numberofEmployees++;
}
Employee(){
name = "not-set";
year = 0;
surname = "not-set";
salary = 0.0;
}
void calculateSalary(){
salary = 2310 + 2310 * year * 12 / 100.0;
}
void printInfo(){
cout << name << " " << surname << " " << "(" << year << ")" << " " << salary << "TL/month" << endl;
}
};
int main()
{
Employee person1(4,"Berk","Kandemir");
cout << Employee::numberofEmployees << endl;
Employee person2(8,"Esat","Kandemir");
cout << Employee::numberofEmployees << endl;
Employee person3(20,"Paul","Walker");
cout << Employee::numberofEmployees << endl;
person1.calculateSalary();
person2.calculateSalary();
person3.calculateSalary();
person1.printInfo();
person2.printInfo();
person3.printInfo();
return 0;
}