I have a linker error and I don't seem to figure out:
The default constructor sets name to “Unknown”, Office Number to nextOfficeNo, Employee number to the value of nextEmpId, Department number to 0, Employee Position to Entry level, year of experience to 0, and salary to 0. It also ensures that the values of all static attributes are incremented by 1.
The second constructor sets the attributes based on what is passed to the function. The value of Employee Salary would still be set to 0 and the values of Office Number and Employee number are set to nextOfficeNo and nextEmpId, respectively. Again, the constructor should increment the values of all static attributes by 1. also; The value of totalNumOfEmployees must be initialized to 0 before creating any object, be incremented upon creating each object of class Employee (in every constructor), and be decremented when an object of class Employee goes out of scope (in destructor).
The value of nextEmpId must be initialized to 1000 before creating any object, and must be incremented upon creating each object of class Employee in every constructor.
The value of nextOfficeNo must be initialized to 10 before creating any object, and must be incremented upon creating each object of class Employee in every constructor.
this is my header class:
#include <iostream>
#include <string>
using namespace std;
class Employee
{
private:
string name;
const long officeNo;
const long empId;
int deptNo;
char empPosition; // ‘E’: entry level, ‘M’: manager, ‘D’: Director, ‘P’:Project_leader
int yearOfExp;
float salary;
static int totalNumofEmployees;
static int nextEmpId;
static int nextOfficeNo;
public:
Employee();
~Employee();
Employee(string theName, int theDeptNo, char theEmpPosition, int theYearOfExp);
void Print() const ;
void GetInfo();
friend void setSalary(Employee& );
};
and this is my CPP class:
I have the problems in my constructors:
#include "Employee.h"
#include <string>
#include <iostream>
Employee::Employee()
: officeNo(nextOfficeNo), empId(nextEmpId)
{
name = "Unknown";
deptNo = 0;
empPosition = 'E';
yearOfExp = 0;
salary = 0;
totalNumofEmployees = 0;
nextEmpId = 1000;
nextOfficeNo = 10;
totalNumofEmployees++;
nextEmpId++;
nextOfficeNo++;
}
Employee::Employee(string theName, int theDeptNo, char theEmpPosition, int theYearOfExp)
: officeNo(nextOfficeNo), empId(nextEmpId)
{
name = theName;
deptNo = theDeptNo;
empPosition = theEmpPosition;
yearOfExp = theYearOfExp;
salary = 0;
totalNumofEmployees = 0;
nextEmpId = 1000;
nextOfficeNo = 10;
totalNumofEmployees++;
nextEmpId++;
nextOfficeNo++;
}
here are the errors:
{Undefined symbols for architecture x86_64:
"Employee::nextOfficeNo", referenced from:
Employee::Employee() in Employee.o
Employee::Employee(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, char, int) in Employee.o
"Employee::totalNumofEmployees", referenced from:
Employee::Employee() in Employee.o
Employee::Employee(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, char, int) in Employee.o
Employee::~Employee() in Employee.o
Employee::Print() const in Employee.o
"Employee::nextEmpId", referenced from:
Employee::Employee() in Employee.o
Employee::Employee(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, char, int) in Employee.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
}