IT lexicon › Programming › RTTI

RTTI

Programming På svenska → Updated: 2026-11-07

Run-time type information: the type data a C++ compiler bakes into the binary so that typeid and dynamic_cast can ask an object what it really is.

Every polymorphic class gets a std::type_info object, and under the Itanium ABI a pointer to it sits in the vtable, in the slot just before the one the object's vtable pointer points at. That's why only classes with virtual functions carry dynamic type information. The symbols are easy to spot: _ZTI for the object, _ZTS for the name string.

dynamic_cast may have to walk the class hierarchy at run time and is noticeably slow, especially across shared libraries, where types are sometimes compared by name string. The type data also costs space for every class. Plenty of large projects therefore build with -fno-rtti or MSVC's /GR-. LLVM does so itself and rolls its own isa<> and dyn_cast<> on top of a hand-maintained type field.

← Back to the lexicon