5.1. Types of Inheritance (level) #
Created Sunday 26 April 2020
- Single Inheritance: A->B
A single link.
- Multilevel Inheritance: A->B->C…
Multiple levels from the same class. Like an LL.
- Hierarchical Inheritance:
Multiple base classes from a single class.
- Multiple Inheritance(inhertiting from multiple base classes) - This is of height 1.
Multiple base classes are inherited by a derived class. Multiple Inheritance is at the core of making ‘new’ things from existing ones.
- We have two types: Chain length, number of parents and number of children.
- What happens if I create a data member/member function which is present in the base class.
- There should be some kind of overridding that takes place.
- The parent parts go out of scope, unless called explicitily.(Simplest)
- In other words, we look in the nearest scope first. If we need the parents version, we use:
- What happens if the derived class has two(or more) base classes which have the same data/member member function. **(Multiple inheritance) **
- It is ambiguous. We’ll have to *specify *which function to use. Using parent : : fname() Just prepend Parent:: before the data member/member function.
- If the inheritance had different modes for different parents, we **still **cannot distinguish between functions as here is no way to access public/private explicitly.