Skip to content

Implementation of polymorphic type

在cppreference Object#Polymorphic objects中给出了这个问题的一个大致解答:

Within each polymorphic object, the implementation stores additional information (in every existing implementation, it is one pointer unless optimized out), which is used by virtual function calls and by the RTTI features (dynamic_cast and typeid) to determine, at run time, the type with which the object was created, regardless of the expression it is used in.

对于polymorphic object的,在使用它的时候,一个非常重要的topic是: 得到dynamic type entire objec,因为它们一般都是通过static type subobject来进行使用的。