90 likes | 613 Views
Inheritance. Topics. Inheritance Constructors and Inheritance Function Over-riding (Redefinition) The Stringstream class Shadowing Variables Destructors and Inheritance Pointers and Inheritance Upcasting and Downcasting Multiple Inheritance. Objectives.
E N D
Topics Inheritance Constructors and Inheritance Function Over-riding (Redefinition) The Stringstream class Shadowing Variables Destructors and Inheritance Pointers and Inheritance Upcasting and Downcasting Multiple Inheritance
Objectives After completing this topic, students should be able to: Correctly design and use classes that use public inheritance in a C++ program * Know how to correctly call the parent constructor * know how to over-ride functions in the parent class Write functions that generate a string representation of a class, using the stringstream class Describe the differences between upcasting and downcasting and know when to safely use each Correctly use multiple inheritance in a program
Inheritance is the act of deriving a new class from an already existing class. It is analogous to creating a new house blueprint from an existing one. Inheritance is useful when we find a natural hierarchical relationship between classes. Inheritance makes it possible to re-use existing code, thus saving time and minimizing bugs.
Ambiguity Errors One of the major issues with multiple inheritance is ambiguity. For example, suppose that the House class and Vehicle class both have a function named turnLightsOn. What happened in the following case: MotorHome myRV; myRV.turnLightsOn( ); the compiler gives you an ambiguity error.