Virtual tables and virtual pointers for multiple virtual inheritance and type casting

后端 未结 3 1515
你的背包
你的背包 2021-02-04 13:48

I am little confused about vptr and representation of objects in the memory, and hope you can help me understand the matter better.

  1. Consider B inhe

3条回答
  •  深忆病人
    2021-02-04 14:10

    1. That seems correct to me. It's not wrong as if you're using a A pointer, you only need what A provide plus maybe B functions implementations that are available from the A vtable (there can be several vtable, depending on compiler and hierarchy complexity).
    2. I'd say yes, but it's compiler implementation dependant so you don't really have to know about it.
    3. and 4. Read farther.

    I would recommend reading Multiple Inheritance Considered Useful , it's a long article but it makes things clearer about the subject as it explains in great details how inheritance works in C++ (the figures links don't work but they are available at the bottom of the page).

提交回复
热议问题