Do C ++ POD types have RTTI?

As I understand it, how RTTI is implemented in various C ++ compilers (for example, GCC), a pointer to type_info data is stored in the vtable data of each class.

And also, as mentioned here , the POD type may not have a vtable .

But if POD types may not have a vtable , then where is the pointer to type_info ? I know that it is implementation-specific, but it would be better to know about the C ++ compiler (e.g. GCC).

+5
c ++ rtti vtable
source share
1 answer

There are two types of types (for RTTI purposes): polymorphic types and non-polymorphic types. A polymorphic type is a type that has a virtual function on its own or inherited from the base class. A non-polymorphic type is everything else; this includes POD types, but also includes many other types.

If you have a pointer / reference to the polymorphic type T , and you call typeid on it, the type_info that you return is optionally type_info , you will return to typeid(T{}) . Instead, it is a true dynamic type of object: the most derived class.

If you have a pointer / reference to a non- polymorphic type T , typeid will always return type_info for T Non-polymorphic types always assume that a pointer / reference is precisely its static type.

POD types are not polymorphic, but a huge number of types are also not polymorphic.

+8
source share

All Articles