1 / 6

Inheritance

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.

Download Presentation

Inheritance

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Inheritance

  2. 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

  3. 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

  4. 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.

  5. Example and Terminology

  6. 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.

More Related