Having problems with the code...error LNK2001: unresolved external symbol "private: static int Employee::numEmployees"


// Program Name: Basic User Interface
// Programmer: Alicia Long
//CIS247C: Week 3 lab
//Program Description: Provide a description of the program

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

class Employee
{
private:
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;
static int numEmployees;

public:
Employee();
Employee(string fname, string lname, char gen, int dep, double salary);
double calculatePay();
void displayEmployee();
string getFirstName();
void setFirstName(string fname);
string getLastName();
void setLastName(string lName);
char getGender();
void setGender(char gen);
int getDependents();
void setDependents(int dep);
double getAnnualSalary();
void setAnnualSalary(double sal);
void DisplayApplicationInformation();
void DisplayDivider(string);
string GetInput(string);
void TerminateApplication();
void setAnnualSalary(string sal);
static int getnumEmployees();
static void setnumEmployees(int numEmp);
};

Employee::Employee()
{
firstName = "Not given";
lastName = "Not given";
gender = ('U');
dependents = 0;
annualSalary = 20000;
numEmployees++;
}

Employee::Employee(string first, string last, char gen, int dep, double salary)
{
firstName = first;
lastName = last;
gender = gen;
dependents = dep;
annualSalary = salary;
numEmployees++;
}

string Employee::getFirstName()
{
return firstName;
}

void Employee::setFirstName(string newFirstName)
{
firstName = newFirstName;
}

string Employee::getLastName()
{
return lastName;
}

void Employee::setLastName(string newLastName)
{
lastName = newLastName;
}

char Employee::getGender()
{
return gender;
}

void Employee::setGender(char)
{
gender = gender;
}

int Employee::getDependents()
{
return dependents;
}

void Employee::setDependents(int newDependents)
{
dependents = newDependents;
}

double Employee::getAnnualSalary()
{
return annualSalary;
}

void Employee::setAnnualSalary(double newAnnualSalary)
{
annualSalary = newAnnualSalary;
}

void Employee::displayEmployee()
{
cout << endl;
cout << "Employee Information" << endl;
cout << "----------------------------------" << endl;
cout << "Employee Name: " << setw(8) << firstName << " " << lastName << endl;
cout << "Gender: " << setw(12) << gender << endl;
cout << "Dependents: " << setw(8) << dependents << endl;
cout << showpoint << fixed << setprecision(2);
cout << "Annual Salary: " << setw(5) << "$" << annualSalary << endl;
cout << "Weekly Salary: " << setw(5) << "$" << calculatePay() << endl;
cout << endl;
}

double Employee::calculatePay()
{
return annualSalary/52;
}

void DisplayApplicationInformation()
{
cout << "Welcome the Basic User Interface Program" << endl;
cout << "CIS247, Week 3 Lab" << endl;
cout << "Name: Alicia Long" << endl << endl;
};

string GetInput(string inputType)
{
string strInput;
cout << "Please enter your "<< inputType << endl;
cin >> strInput;
return strInput;
}

void DisplayDivider(string outputTitle)
{
cout << "\n***************************" << outputTitle <<"***************************" << "\n";
}

void DisplayDivider2(string outputTitle)
{
cout << "\n" << outputTitle << endl;
cout << "\n________________________________________________________________" << "\n";
}

void TerminateApplication()
{
cout << "Thank you for using the Basic User Interface program";
}

void main()
{
DisplayApplicationInformation();
DisplayDivider("Employee 1");
Employee Employee1;

string firstName = GetInput("First Name");
Employee1.setFirstName(firstName);

string lastName = GetInput("Last Name");
Employee1.setLastName(lastName);

string gender = GetInput("Gender");
Employee1.setGender(gender.at(0));

string dependents = GetInput("Dependents");
Employee1.setDependents(atoi(dependents.c_str()) );

string annualSalary = GetInput("Annual Salary");
Employee1.setAnnualSalary(atof(annualSalary.c_str()) );

DisplayDivider2("Employee Information");
Employee1.displayEmployee();
cout << endl;

Employee employee2("Mary", "Noia", 'F', 5, 24000.0);

DisplayDivider("Employee 2");
DisplayDivider2("Employee Information");
employee2.displayEmployee();

system("pause");
}

When using a static member variable you have to define it outside of the class before you can use it.

int Employee::numEmployees = 0;

http://en.cppreference.com/w/cpp/language/static
THANK YOU!!! So much
Topic archived. No new replies allowed.