What is the VTable Layout and VTable Pointer Location in C++ Objects in GCC 3.x and 4.x?

前端 未结 2 525
遥遥无期
遥遥无期 2020-12-01 23:46

I am looking for details of the VTable structure, order and contents, and the location of the vtable pointers within objects.

Ideally, this will cover single inheri

2条回答
  •  攒了一身酷
    2020-12-02 00:07

    Most of the compiler implementations that I have seen just "embed" the base object into the derived object. It becomes irrelevant where the vtable is kept because the relative offset into the object will just be added at compile time as references are evaluated.

    Multiple and virtual inheritance are more complicated and can require a different offset depending on what is being accessed.

    I highly recommend reading this article on Code Project: The Impossibly Fast C++ Delegates

    It brilliantly gives a broad picture of how different compilers handle various aspects of inheritance. Fantastic read if you are interested in the low level workings of different compilers.

    Edit: I linked the wrong article over there. Corrected.

提交回复
热议问题