14. Reusing Code in C++

In this chapter you’ll learn about the following:

Has-a relationships

• Classes with member objects (containment)

• The valarray template class

• Private and protected inheritance

• Multiple inheritance

• Virtual base classes

• Creating class templates

• Using class templates

• Template specializations

One of the main goals of C++ is to facilitate the reuse of code. Public inheritance is one mechanism for achieving this goal, but it’s not the only one. This chapter investigates other choices. One technique is to use class members that are themselves objects of another class. This is referred to as containment or composition or layering. Another option is to use private or protected inheritance. Containment, private inheritance, ...

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.