12.4. RTTI Applications

This section examines several applications with RTTI. We'll show you how RTTI determines object types in class hierarchies, extends class libraries for new classes, and controls object behaviors. These applications demonstrate the power of RTTI and its important role as a portable solution to class library design.

Working with Class Hierarchies

This example applies RTTI to the Shape class hierarchy from Chapter 11 (Listing 11.23 on page 531). We'll start with the Shape abstract base class.

Listing 12.1. Abstract class Shape interface
 class Shape { // abstract base private: static int count; // static data member public: Shape() { count++; } // constructor Shape(const Shape &) { count++; } // copy constructor virtual ~Shape() ...

Get Navigating C++ and Object-Oriented Design 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.