(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:
- public inheritance, an 'is-a-kind-of' relationship, the most commonly used mode of inheritance
- protected inheritance, an obscure type of relationship
- private inheritance, an 'is-implemented-in-terms-of' relationship [1]
Examples
advice
- Prefer composition to inheritance [2]
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
External links
References
-
- Scott Meyers. Effective C++ (3rd edition).ISBN:0-321-33487-6. Item 39: 'Use private inheritance judiciously'
-
- 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'.