Does every object of virtual class have a pointer to vtable?

后端 未结 9 906
借酒劲吻你
借酒劲吻你 2020-12-14 10:54

Does every object of virtual class have a pointer to vtable?

Or only the object of base class with virtual function has it?

Where did the vtable stored? code

9条回答
  •  失恋的感觉
    2020-12-14 11:22

    Vtable is a per class instance, i.e., if I have 10 objects of a class which has a virtual method there is only one vtable which is shared among all the 10 objects.

    All the 10 objects in this case point to same vtable.

提交回复
热议问题