understanding vptr in multiple inheritance?

后端 未结 5 2127
暗喜
暗喜 2021-01-30 11:59

I am trying to make sense of the statement in book effective c++. Following is the inheritance diagram for multiple inheritance.

5条回答
  •  不知归路
    2021-01-30 12:15

    I think D needs 2 or 3 vptrs.

    Here A may or may not require a vptr. B needs one that should not be shared with A (because A is virtually inherited). C needs one that should not be shared with A (ditto). D can use B or C's vftable for its new virtual functions (if any), so it can share B's or C's.

    My old paper "C++: Under the Hood" explains the Microsoft C++ implementation of virtual base classes. http://www.openrce.org/articles/files/jangrayhood.pdf

    And (MS C++) you can compile with cl /d1reportAllClassLayout to get a text report of class memory layouts.

    Happy hacking!

提交回复
热议问题