C++ Programming Guide

Static and Dynamic Types

In C++, pointers to classes have a static type, the type written in the pointer declaration, and a dynamic type, which is determined by the actual type referenced. The dynamic type of the object could be any class type derived from the static type. In the following example, ap has the static type A* and a dynamic type B*.


class A {};
class B: public A {};
extern B bv;
extern A* ap = &bv;

RTTI allows the programmer to determine the dynamic type of the pointer.