virtual-table

Why is there a top_offset in VTT implemented by gcc?

不想你离开。 提交于 2019-12-23 06:02:53
问题 Here is a detailed description of VTT in the top-voted answer.But the answer does not explain why is there a top-offset in the VTT. From my point of view,when we down_cast a base pointer to derived pointer, the compiler already knows the offset needed to be adjusted in compile time (when there is no virtual derivation) ,so there is no need to store a top_offset in situation below: class A { public: int a; }; class B { public: int b; virtual void w(); }; class C : public A, public B { public:

Why is there a top_offset in VTT implemented by gcc?

青春壹個敷衍的年華 提交于 2019-12-23 06:02:03
问题 Here is a detailed description of VTT in the top-voted answer.But the answer does not explain why is there a top-offset in the VTT. From my point of view,when we down_cast a base pointer to derived pointer, the compiler already knows the offset needed to be adjusted in compile time (when there is no virtual derivation) ,so there is no need to store a top_offset in situation below: class A { public: int a; }; class B { public: int b; virtual void w(); }; class C : public A, public B { public: