Introduction to OOP: Chapter 15 : Case Study: Container Classes [next] [previous] [audio] [real] [text]

Containers that Hold Only Pointers

In many applications, containers will be used only to hold pointers, not values themselves.

This is often due in part to the fact that only pointers or references can be true polymorphic variables in C++.

In these situations we can create a generic link class that maintains a void pointer, and get by with only subclassing the list class.

Values must be cast back to correct type after they are removed from container.

Intro OOP, Chapter 15, Slide 11

This is similar to the way that Java containers hold values in variables of type Object.