The following program is part of an assignment using a base class and derived classes to calculate payroll.
When I compile I get the message:
[Linker error] undefined reference to `vtable for payroll'
C:\DOCUME~1\will\LOCALS~1\Temp\ccCmbaaa.o(.text+0x388) In function `ZN7payrollD1Ev':
[Linker error] undefined reference to `vtable for payroll'
C:\DOCUME~1\will\LOCALS~1\Temp\ccCmbaaa.o(.text+0x388) ld returned 1 exit status
I compile the code using VStudio 2005 and get an error on the line
hourly findgrosspay();
I assume you're trying to call the findgrosspay method on the hourly class. You have to instantiate the class as an object before invoking the function.
1) hourly findgrosspay(); is not the correct syntax for calling a member function on a class. If you want to call hourly memberfunction you have to be explicit hourly::findgrosspay(); by using the ::
2) You need to uncomment the void payroll::findgrosspay() function definition otherwise you'll get unresolved external for the findgrosspay on the payroll class. The reason is because you defined the function as virtual which means there has to be a definition on the payroll class. If you don't want to implement on the payroll class and force inherited class to implent than use pure virtual by replacing
virtual void findgrosspay();
with
virtual void findgrosspay() = 0;
I've been pointed in the right direction. I will set out to restructure the code. I've received a very good sample of what it should look like. This is how we learn.