previous | start | next

Result

The result:

int main()
{
  Employee e1("Bob", 45000.00);
  Manager m1("Alex", 60000.00);

  cout << e1.getName() " has bonus " 
        << e1.getBonus() << endl;
  // Prints: Bob has bonus 450

  cout << m1.getName() " has bonus " 
        << m1.getBonus() << endl;
  // Prints: Alex has bonus 120000
  

  e1 = m1;  

  cout << e1.getName() " has bonus " 
        << e1.getBonus() << endl;
  // Prints: Alex has bonus 600
   

So although e1's name has been changed from Bob to Alex and e1's salary has been changed from 45000 to 60000 e1 still uses the virtual function table for Employee.

So e1's bonus is calculated at .01 * salary instead of 2 * salary.



previous | start | next