The Secret Life of C++: Day 2: Run Time Type Information

Run time type information allows us to do complicated things at runtime, like dynamic_cast<>.

As we saw in our VTable examples, there is a pointer to a type info structure in every vtable of every class. This allows us to look at this object at runtime and find out details about the class we have. All we have to know is the vtable for an object, and we can, for example, find the name of its type.

Lets look at a quick example that use dynamic_cast<>. dynamic-cast.cc, dynamic-cast.s, dynamic-cast.listing.

Its clear that the __dynamic_cast method does all of the work. Lets see what its implementation looks like: __dynamic_cast.cc


Richard Tibbetts
Last modified: Tue Jan 20 23:53:13 EST 2004