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

后端 未结 9 912
借酒劲吻你
借酒劲吻你 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:23

    A VTable is an implementation detail there is nothing in the language definition that says it exists. In fact I have read about alternative methods for implementing virtual functions.

    BUT: All the common compilers (ie the ones I know about) use VTabels.
    Then Yes. Any class that has a virtual method or is derived from a class (directly or indirectly) that has a virtual method will have objects with a pointer to a VTable.

    All other questions you ask will depend on the compiler/hardware there is no real answer to those questions.

提交回复
热议问题