How does virtual inheritance work?

  • Does virtual inheritance use vTable? If yes or no, then how is it implemented.
  • How does virtual inheritance behave in memory?
  • Any alternative for virtual inheritance

Really appreciate the conceptual explanation.

+6
source share
1 answer

Virtual inheritance is implemented differently depending on the compiler.

1) Yes, vc and gcc use the vTable pointer. But vc has another ref pointer as a virtual base pointer.

2) For classic virtual inheritance, such as Left <Top; Right <Upper; Bottom <Left and Right Stack should look like this:

Left.vptr // -> to its vtable Left::element_in_left Right.vptr Right::element_in_right Bottom::element_in_bottom Top::element_in_top 

Programs use vptr to search for vtable, for gcc there is a virtual base offset value in a viable form. vptr + base offset will give the parent address.

3) I'm not sure what you mean. There are various ways to implement it in C ++ compilers. And other languages ​​have their own ways of binding functions.

+1
source

Source: https://habr.com/ru/post/924815/


All Articles