Questions tagged [vtable]

A virtual table, or vtable, is a technique used to implement polymorphic functions with dynamic dispatch

In C++ (and other languages) a vtable contains pointers to a polymorphic type's virtual functions, allowing the language runtime to do dynamic dispatch by looking up the relevant entry in an object's vtable. The lookup is generally implemented by accessing the table at a fixed offset determined at compile time.

A object of a polymorphic type contains a pointer to its class' vtable and the vtable contains a pointer to the final overrider of each virtual function (i.e. the implementation of the function in the most-derived type that overrides the function.)

617 questions
-5
votes
2 answers

Why does a virtual function call from constructor work sometimes but not others?

The general rule of thumb is not to call a virtual function from a constructor because it can lead to unpredictable behavior. So why does it work sometimes? I recently wrote a couple of base classes with pure virtual functions, and accidentally…
mousebyte
  • 61
  • 7
-5
votes
1 answer

Function resolution from vtable in C++

I have a confusion regarding vtable after reading more about name mangling. for ex: class Base { public: virtual void print() { } }; class A : public Base { public: void hello() { .... } void print() { …
Gilson PJ
  • 3,443
  • 3
  • 32
  • 53
1 2 3
41
42