Search code examples
c++rttidynamic-binding

Does RTTI mean Dynamic Binding?


In C++, does Run-Time Type Information (RTTI) mean dynamic binding?


Solution

  • RTTI means additional information is included in the compiler output so that runtime code can know details about the source code classes and types that would normally be thrown away in compilation.

    For example, the machine code doesn't need to know the name of a function in order to call a function - calling a function in machine code only needs to know the address of the target function.

    Another example: The compiled machine code doesn't need to know the name of a class type at runtime. But if you want to build an automatic serialization library, you'll probably want to know the text name of each class so you can write it to the output stream. The class name is RTTI.

    If by dynamic binding you mean the ability to find and invoke methods or properties by string name at runtime that were not known at compile time, then yes, RTTI is a resource that can be used for that purpose.