Next: Uses of Run-Time Up: A General-Purpose Run-Time Type Previous: Introduction

The Concept of Run-Time Type Information

 

Run-time type information (RTTI) can be seen as an extension to static (compile-time) type information. It offers to the user information about pointers and references which is similar to the type information a compiler maintains while compiling a C++ program. Basically, RTTI comes in two flavours: getting type information from run-time elements like pointers and references and getting type information from 'static' elements like classes.

Since this information is to be passed to the user (who will manipulate it at run-time), we need a way to encode it in some run-time object. Such an object is called a typeid and keeps all information which characterizes a C++ type. In other words, for any C++ type there is a typeid object which encodes its type. In the rest of this paper we shall identify the C++ type concept with the C++ class concept, thus ignoring basic types like int, float, etc.

To precise notions, a typeid for a pointer or reference will represent the type of the actual object pointed by that pointer or referred to by that reference. The typeid for a class will obviously represent the type of that class.



Alexandru Telea