Public Inheritance Considerations
Naturally, adding inheritance to a program brings up a number of considerations. Let’s look at a few.
Is-a Relationship Considerations
You should be guided by the is-a relationship. If your proposed derived class is not a particular kind of the base class, you shouldn’t use public derivation. For example, you shouldn’t derive a Programmer
class from a Brain
class. If you want to represent the belief that a programmer has a brain, you should use a Brain
class object as a member of the Programmer
class.
In some cases the best approach may be to create an abstract data class with pure virtual functions and to derive other classes from it.
Remember that one expression of the is-a relationship is that a base class ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.