INST 201 Lecture Notes - Lecture 11: Multiple Inheritance
Document Summary
In the class definition, separate the superclasses by commas: class mysubclass : public superclass1, public superclass2. Be sure to use the scope operator generously; if two classes have the same variable name or function name, you need to be specific. Consider the following: class mom{ protected: int age; /* the rest of class mom */ class dad{ protected: int age; /* the rest of class dad */ class kid : public mom, public dad public: int get_age() {return age;} // note the problem Class kid attempts to access variable age in its get_age() function; but it is unclear whether this means dad::age or mom::age, so it is necessary to specify. A similar problem occurs when two superclasses share the same base class. Suppose there were a base class grandparent with protected data member height, and mom and dad were subclasses of grandparent: class grandparent{ protected: int height;