Tools.h++ Manual
104011 Tandem Computers Incorporated 13-1
Templates 13
13.1 Introduction
Ever since Version 2.0, Tools.h++ has traditionally offered two types of
collection classes: the so-called "generic" collection classes and the Smalltalk-
like collection classes. Each had its advantages and disadvantages. The
Smalltalk-like classes offer a pleasant programming interface, code reuse, and a
consistent interface. However, they actually collect pointers to a common base
class (
RWCollectable
), requiring that all collected objects inherit from this
class—the actual type of the class is unknown at runtime. This requires the
programmer to rely on some other kind of information, either the
isA()
function or some logical inference, to decide whether it is safe to "downcast"
the pointer to an
RWCollectable
to a pointer to the derived class. A recent
language extension
1
holds the promise that such downcasting will at least be
standardized by the language. However, the programmer will always have to
remember to perform the check. The check may also fail: an object's
inheritance hierarchy may make the type cast impossible and the prudent
programmer must be prepared for this.
1. See, for example, Josée Lajoie’s article “The new language extensions” in the July-August 1993 issue of The C++
Report.