How compiler implements RTTI

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aoz
    New Member
    • Feb 2008
    • 1

    How compiler implements RTTI

    Hi,

    I basically want to know how compilers ( e.g "gcc" ) handles RTTI internally.Can someone please help.

    Bibaswan
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    RTTI only works where virtual functions are involved (otherwise you already know the type). Using it requires the typeid and type_info classes. These classes use a database attached to each variable that contains the correct type. Just enabling RTTI creates this database for every variable that is a pointer (or reference) to a class with virtual functions.

    For objects that don't have virtual methods, the type of the object is already known and that is what is returned by typeid. That means if you typecast a double* to an int* and do a typeid, you will get int as an answer.

    Comment

    Working...