Abstract class

1>CIS247_Wk6Lab_EugeneYoung.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall Employee::displayEmployee(void)" (?displayEmployee@Employee@@UAEXXZ) referenced in function "public: virtual void __thiscall Hourly::displayEmployee(void)" (?displayEmployee@Hourly@@UAEXXZ)
1>CIS247_Wk6Lab_EugeneYoung.obj : error LNK2019: unresolved external symbol "public: virtual double __thiscall Employee::calculatePay(void)" (?calculatePay@Employee@@UAENXZ) referenced in function "public: virtual double __thiscall Salaried::calculatePay(void)" (?calculatePay@Salaried@@UAENXZ)
1>C:\Users\Ogie\documents\visual studio 2010\Projects\CIS247_Wk6Lab_EugeneYoung\Debug\CIS247_Wk6Lab_EugeneYoung.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I tried to make an abstract class with a couple of virtual functions and got these errors.
here is a snippet of my code:

class Employee
{ //declare static variable accessible, which is accessible by all objects of the class
static int numEmployees;

protected:
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;

//declare a benefits object
Benefit benefits;

public:

virtual double calculatePay() = 0;
virtual void displayEmployee() = 0;
.
.
.
};
If you are trying to instantiate an Employee, you cant since you made the class pure virtual. If your instantiating a derived class make sure it implements the pure virtual methods.
In function displayEmployee() of class Hourly you call function
displayEmployee() of class Employee which was not defined.

The same is valid for function calculatePay() of the same class Employee that is called from function calculatePay() of class Salaried.

If you want to call pure virtual functions of a base abstract class in a derived class you have to define them. For example


1
2
3
4
5
6
7
8
9
10
11
12
class Employee
{ 
...
public:

virtual double calculatePay() = 0;
virtual void displayEmployee() = 0;
...
};

double Employee::calculatePay() { /* some code */ }
void Employee::displayEmployee() { /* some code */ } 

Last edited on
Topic archived. No new replies allowed.