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
0
votes
1 answer

How to enforce parent / derived relationship of two independent classes inside a container?

Consider the following class definitions: #include class CParty { public: CParty(); virtual ~CParty(); int m_nId; }; class CPartyEx : public CParty { public: CPartyEx(); ~CPartyEx(); std::string m_sName; }; class…
Aurora
  • 1,334
  • 8
  • 21
0
votes
2 answers

Undefined symbol vtable

Compiling Qt cpp code and receiving this error: Running ld for x86_64 ... Undefined symbols for architecture x86_64: "vtable for HelixButton", referenced from: HelixButton::HelixButton(QString const&, QWidget*) in helixQtCmd.o …
Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89
0
votes
1 answer

undefined reference to 'vtable of derived_class'

I've seen all the other answers to this error but i've tried all I could find and still nothing worked. here's my code: class Train{ protected: string myID; int myCap; int myPass; char myType; public: …
0
votes
3 answers

seeing undefined reference to `vtable for CollidingMice'

I'm modifying a Qt example 'collidingmice' which comes with the Qt code. In the original source, the QApplication contains QView and QScene, but I made a class CollidingMice containing the QView and QScene to kill the view and scene using keyboard…
Chan Kim
  • 5,177
  • 12
  • 57
  • 112
0
votes
1 answer

hook COM interface throw vTable

I'm trying hook custom Credentential Provider UI, based on ICredentialProvider interface. Using this guide(Vtable Patching) , i'm succesufly hook COM interface. But trouble with hooking GetCredentenialAt method, i'm set vtable index equal to 10, and…
r1se
  • 67
  • 1
  • 1
  • 6
0
votes
3 answers

Unknown segmentation fault involving vtable lookup

So I messing around with virtual functions, trying to find a way to mitigate their cost, and I encountered an entirely unknown error. My entire code follows; #include #include class Base { public: virtual…
user4578093
  • 231
  • 1
  • 3
  • 10
0
votes
1 answer

How to Call COM unmanaged code at Runtime from C#.NET using ITypeLib and ITypeInfo?

I need to call unmanaged COM code from C#.NET. By loading unmanaged COM Type libraries from (LoadTypeLibEx), I am able to iterate over all exposed types by COM TLB. I need to know the addresses to call those exposed methods at runtime or by…
Usman
  • 2,742
  • 4
  • 44
  • 82
0
votes
2 answers

C++: Help understanding this line of code

I was looking for a way to access the vtable directly through a pointer and came across this post: http://www.codeproject.com/Tips/90875/Displaying-vtable-when-debugging It works fine and I can invoke functions through the vtable entries. But I'm…
madu
  • 5,232
  • 14
  • 56
  • 96
0
votes
2 answers

C++ child constructor and VPTR

In many sources, books etc. are written "don't call this->virtualFunction in child class constructor" and in some sources explain why you mustn't do it. Because at the moment of construction class isn't created at all. So virtual function that will…
Talkin
  • 3
  • 2
0
votes
1 answer

C++: How to look at vptr/ vtable contents

Every C++ object that has a virtual function has a vptr that points to a vtable. How can I see what this vptr is, and the contents it is point to? I understand this is compiler dependent and it could put vptr anywhere in the object memory space. But…
madu
  • 5,232
  • 14
  • 56
  • 96
0
votes
3 answers

C++ Polymorphism. Why is this working?

Shouldn't this be incorrect ? : A* apb = (A*)&b; //a pointer to b I would expect an error, or at least a warning. Why is this not giving me any warning either in Visual C++ 2013 (v120) or in g++ (gcc 4.8.2) ? #ifndef A_H #define A_H #include…
Scott
  • 383
  • 3
  • 10
0
votes
2 answers

Link error missing vtable

I'm defining a class 'function' and two others classes 'polynomial' and 'affine' that inherit from 'function'. class function { public: function(){}; virtual function* clone()const=0; virtual float operator()(float…
dada
  • 1,390
  • 2
  • 17
  • 40
0
votes
1 answer

Which performs faster? vtable look-up with N derived types, or std::map look-up with N elements?

#include #include #include struct Base { virtual void foo() {} }; struct A : Base { void foo() {} }; struct B : Base { void foo() {} }; struct C : Base { void foo() {} }; A* protoA = new A; B* protoB = new B; C* protoC =…
prestokeys
  • 4,817
  • 3
  • 20
  • 43
0
votes
1 answer

How many V Tabels will be created?

class Base { public: virtual void function1() {}; virtual void function2() {}; }; class D1: public Base { public: virtual void function1() {}; }; class D2: public Base { public: virtual void function2() {}; }; for the above…
NDestiny
  • 1,133
  • 1
  • 12
  • 28
0
votes
0 answers

C++ new operator with valid vtable without calling constructor

Is it possible to create an instance of a class on a heap without calling default constructor and with a valid vtable for inheritance? Let me demonstrate what I will like to do: class A { protected: virtual void _fake_static_method() { …
Alexander
  • 471
  • 4
  • 18