O'Reilly logo

C++ Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Class Templates

Inheritance (public, private, or protected) and containment aren't always the answer to a desire to reuse code. Consider, for example, the Stack class (Chapter 10), the Queue class (Chapter 12), and the ArrayDb class (this chapter). These are all examples of container classes, which are classes designed to hold other objects or data types. The Stack class, for example, stored unsigned long values. You could just as easily define a stack class for storing double values or String objects. The code would be identical other than for the type of object stored. However, rather than writing new class declarations, it would be nice if you could define a stack in a generic (that is, type-independent) fashion and then provide a specific ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required