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
6
votes
2 answers

undefined reference to vtable

i have a class afporoills that helps find data in our memory managment module. (dont ask why such a wierd name i have no idea) class afporoills{ void** test(int pos); }; void** afporoills::test(int pos){ int x=(pos<<3)|1023*x; void**…
n00b
  • 5,642
  • 2
  • 30
  • 48
6
votes
2 answers

Guarding against vtable data race in derived destructor

Suppose I have the following code #include #include #include struct FooBase { void start(){ run_condition_ = true; t_ = std::thread([this](){ thread_handler(); }); } …
arynaq
  • 6,710
  • 9
  • 44
  • 74
6
votes
1 answer

What does ZTV,ZTS,ZTI mean in the result of gdb x/nfu "vtable_address"?

1. the code class Parent { public: virtual void Foo() {} virtual void FooNotOverridden() {} }; class Derived : public Parent { public: void Foo() override {} }; int main() { Parent p1, p2; Derived d1, d2; } 2. gdb command (gdb)…
JellyHan
  • 63
  • 3
6
votes
2 answers

undefined reference to vtable - virtual member, classes generated by gsoap

gsoap with its tools wsdl2h and soapcpp2 provided me with a soapStub.h file containing the following: class SOAP_CMAC ns2__SOAPKunden { public: std::string *adresszusatz; // ... public: virtual int soap_type() const { return 7; } …
groovehunter
  • 3,050
  • 7
  • 26
  • 38
6
votes
1 answer

Understanding of vtable in derived classes

I'm trying to undestand some low-level things with virtual table and inheritance. When you create new class by inheriting two classes and adding new virtual functions, where exactly the vptr will be stored? It seems to me, that compiler performs…
renzo
  • 311
  • 1
  • 13
6
votes
3 answers

Why does an abstract class have a vtable?

Regarding this post: For implementations that use vtable, the answer is: Yes, usually. You might think that vtable isn't required for abstract classes because the derived class will have its own vtable, but it is needed during construction:…
Loay
  • 483
  • 3
  • 18
6
votes
4 answers

Would using a virtual destructor make non-virtual functions do v-table lookups?

Just what the topic asks. Also want to know why non of the usual examples of CRTP do not mention a virtual dtor. EDIT: Guys, Please post about the CRTP prob as well, thanks.
nakiya
  • 14,063
  • 21
  • 79
  • 118
6
votes
1 answer

API Hook on a COM object function?

Greetings StackOverflowians, As discovered here, Windows 7 features a bug in which the DISPID_BEFORENAVIGATE2 event does not fire for Windows Explorer instances. This event allows shell extensions to be notified when a navigation is about to take…
Paul Accisano
  • 1,416
  • 1
  • 14
  • 25
6
votes
4 answers

How are vtables implemented in c++ and c#?

Lets have this situation (in c++, in c# classes A,B are interfaces): class A { virtual void func() = 0; }; class B { virtual void func() = 0; }; class X: public A, public B { virtual void func(){ var = 1; } int var;}; X * x = new X; // from what I…
chris
  • 664
  • 1
  • 12
  • 23
6
votes
2 answers

How many vptr will a object of class(uses single/multiple inheritance) have?

How many vptrs are usually needed for a object whose clas( child ) has single inheritance with a base class which multiple inherits base1 and base2. What is the strategy for identifying how many vptrs a object has provided it has couple of single…
Passionate programmer
  • 5,748
  • 10
  • 39
  • 43
6
votes
1 answer

Why can't a vtable contain duplicate functions?

Imagine a project in which there is an interface class like the following: struct Interface { virtual void f()=0; virtual void g()=0; virtual void h()=0; }; Suppose that somewhere else, someone wishes to create a class implementing this…
PBS
  • 1,389
  • 11
  • 20
6
votes
2 answers

What causes "java.lang.IncompatibleClassChangeError: vtable stub"?

What causes "java.lang.IncompatibleClassChangeError: vtable stub"? In our application, we have seen this error pop up randomly and very seldom (just twice so far, and we run it a lot). It is not readily reproducible, even when restarting the app,…
JimN
  • 3,120
  • 22
  • 35
6
votes
2 answers

Does C++ have a static polymorphism implementation of interface that does not use vtable?

Does C++ have a proper implementation of interface that does not use vtable? for example class BaseInterface{ public: virtual void func() const = 0; } class BaseInterfaceImpl:public BaseInterface{ public: void func(){ std::cout<<"called."<
gilbertc
  • 1,049
  • 1
  • 10
  • 19
6
votes
1 answer

Why does the following class have a virtual table?

Suppose I have a diamond inheritance situation as follows: class A{ public: virtual void foo(){}; }; class B: public virtual A{ public: virtual void foo(){}; }; class C: public virtual A{ public: virtual void foo(){}; }; class D: B,…
EpsilonVector
  • 3,973
  • 7
  • 38
  • 62
6
votes
2 answers

what's the meaning of (base->*&Func)() in C++

Here's simple class definitions like class Base{ public: virtual void Func(){ cout<<"Func in Base"<
Qutard
  • 355
  • 2
  • 6