INST 201 Lecture Notes - Lecture 11: Multiple Inheritance

85 views4 pages

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;

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents