(C++) inheritance

March 10, 2018 ยท View on GitHub

Inheritance is a technique to re-use members of a class.

There are multiple types of inheritance:

There are three modes of inheritance:

  1. public inheritance, an 'is-a-kind-of' relationship, the most commonly used mode of inheritance
  2. protected inheritance, an obscure type of relationship
  3. private inheritance, an 'is-implemented-in-terms-of' relationship [1]

Examples

advice

Notes to self

  • When in doubt, don't use inheritance: it is far far easier to correct when you've used composition too long, than the other way around

References

    1. Scott Meyers. Effective C++ (3rd edition).ISBN:0-321-33487-6. Item 39: 'Use private inheritance judiciously'
    1. Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. 2005. ISBN: 0-32-111358-6. Chapter 34: 'Prefer composition to inheritance'.