"Michael C. Starkie" <mi**@bogus.com > wrote...
Car is a class, with four wheel variables. SUV is a class with four
wheel variables. Outback is a class that inherits from Car and SUV.
How many wheel variables does Outback have? (In general, how does
multiple inheritance work?)
Well, in presented hierarchy the Outback object will have 8 wheels.
4 in its Car subobject, 4 in its SUV subobject. However, it would
probably be more correct to define the hierarchy this way:
class FourWheelVehicl e {
Wheel wheels[4];
...
};
class Car : public virtual FourWheelVehicl e { .. };
class SUV : public virtual FourWheelVehicl e { .. };
class Outback : public Car, public SUV { .. };
which will provide you with only one 'FourWheelVehic le' subobject in
Outback, and therefore only four wheels.
The reason I suggest extracting FourWheelVehicl e into a separate
base class is because there is too much common between Car and SUV
to ignore that. The common functionality and implementation should
be placed in the common base class.
Victor