For the constructor example we stated ...

“If Person requires values for ID number

and name, Student requires a grade,

Employee requires an hourly rate, and

StudentEmployee requires a limit on the

number of hours allowed to work per week.”

But it seems reasonable that both Student

and Employee are derived from Person.

So do we have two names and id’s?


If two classes inherit from the same base class, a

descendant class object which inherits from both will

end up with access to two separate base class

objects.

To avoid this duplicate inheritance, use the keyword

virtual ...

class Student : virtual public Person {...};

class Employee : virtual public Person {...};


The compiler will treat Person as though it were a

direct base class of StudentEmployee.

– This is called virtual inheritance.


Now the StudentEmployee class will only have

access to one copy of the Person class.