The getBonus() function in the base class has the qualifier "virtual".
A table of the beginning addresses of the virtual functions for a class is created. The virtual function table.
There is one such table for each class. All values of a given class type use the same virtual function table; that is, a object value of a class type has stored implicitly in the object a pointer to the virtual function table for its class.
Calls to member functions which are virtual functions may be "looked up" in the virtual function table.
Employee and Manager have different virtual function tables.
So a call to the virtual function "getBonus" will be "looked up" in the Employee virtual function table or in the Manager virtual function table DEPENDING on whether the object being used is an Employee or a Manager.
Suppose these are the two implementations of getBonus:
virtual double getBonus() const
{
return 0.01 * salary;
}
virtual double getBonus() const
{
return 2 * getSalary();
}