Inheritance and Derived Classes
- 9.6k Downloads
Suppose we have developed a class for a specific application. If we want to extend the software based on this class to do something slightly different we could modify the class already written. This, however, may not be an ideal solution as we may introduce conflicts with the functionality of the original class. A more suitable approach is to derive a new class that has the features of the original class (modified if required) together with any new features required. This is known as inheritance, and is a very powerful feature of the C++ language. One particularly useful feature of inheritance is that of polymorphism: we may apply the same functionality to instances of both the original class and the derived class, with the correct operations “under the hood” being chosen by the computer based on whether the instance of the class is the original or derived class.