How is polymorphism implemented at a low level in a language such as C ++?

I read in a book that polymorphism is implemented in C ++ by three levels of pointers (using vtable), but are there any other methods for its implementation in C ++.

+4
source share
1 answer

Virtual functions can also be implemented directly using function pointers like this.

struct A { void (*foo)(A *thiz); void (*goo)(A *thiz, int x); }; 

But obviously this is less efficient than regular implementations. And in fact, C ++ implementations may be slightly different when working with inheritance multiplication and virtual base classes.

0
source

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


All Articles