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 get function name against function address by reading co-classs'es vtable?

I need to call the co-class function by reading its address from vtable of COM exposed interface methods. I need some generic way to read addresses. Now I need to call the function, which would have specific address(NOT KNOWN) arguments(parameters)…
Usman
  • 2,742
  • 4
  • 44
  • 82
0
votes
2 answers

Marhal non COM interface to unmanaged code

I've implemented this method in c#: HRESULT CreateSourceVoice( [out] IXAudio2SourceVoice **ppSourceVoice, [in] const WAVEFORMATEX *pSourceFormat, [in] UINT32 Flags = 0, [in] float MaxFrequencyRatio…
Florian
  • 5,918
  • 3
  • 47
  • 86
0
votes
1 answer

Data packing and vtable pointer

This is a follow-up question to the one I posted yesterday: sizeof(myobject) not what I have calculated I create a class and calculate its size using sizeof(myclass). The size is 12 bytes. I then add virtual members, and the size goes up to 24…
0
votes
0 answers

C++ plugin architecture in Linux environment

I always get the below error message : error: undefined reference to 'vtable for a' when I try to do a *ker = (a *)create_a_dll(); how to fix this problem ?? here are my definitions. class base {...}; class a : public base {...}; extern "C" { …
0
votes
2 answers

Understanding output when virtual functions are called directly using vptr

I was going through the code which I got from somewhere to understand how vptr and vtable works. Following is the code with the output class Base1 { virtual void fun1() { cout<< "Base1::fun1()" << endl; } virtual void func1() { cout<<…
cbinder
  • 2,388
  • 2
  • 21
  • 36
0
votes
2 answers

How do I fix an undefined reference to vtable?

I've seen a number of people with similar issues, but the solutions I've seen don't seem to fix my issue, so hopefully someone can see my issue and explain how to fix it or at least direct me to somewhere that can explain it. Here is my code (at…
DeadEli
  • 983
  • 2
  • 13
  • 28
0
votes
1 answer

undefined reference to vtable when calling constructor of base class

I am working on a project for school and I ran into a problem I am not sure how to solve. Here are bits of the code (not the whole classes) and the error message: class CCPU { public: CCPU ( uint8_t…
Johhny-T
  • 27
  • 1
  • 3
  • 9
0
votes
2 answers

Multiple classes with the same name causing vtable problems

I have an interesting problem that crept up and I was wondering why GCC/G++ doesn't catch this and throw some kind of error. Apologies for how many files this takes, but I've reduced the problem as much as possible. Interface.H class BaseClass…
Salgar
  • 7,687
  • 1
  • 25
  • 39
0
votes
2 answers

Avoid the overhead of reading the V-Table upon every function-call, when there is only one class in the class-hierarchy

I have a class which may or may not be extended (inherited) by other parties. So I declare every function which is "plausibly-inheritable" as virtual. On my current application, however, this class is never inherited. So it seems wasteful to do so,…
barak manos
  • 29,648
  • 10
  • 62
  • 114
0
votes
6 answers

when allocating memory to an object of base class, does the memory for the derived class is allocated too?

class A { private: int _a; public: //some virtual methods... }; class B : public A { private: int _b; public: //methods.. }; when declaring a pointer of type A like: A* a = new…
Tom
  • 1,203
  • 4
  • 21
  • 36
0
votes
1 answer

Thread safe hooking of DirectX Device

I successfully hooked BeginScene/EndScene methods of DirectX9's DeviceEx, in order to override regions on the screen of a graphics application. I did it by overriding the first 'line' of the function pointed by the appropriate vtable entry (42 for…
MaMazav
  • 1,773
  • 3
  • 19
  • 33
0
votes
3 answers

Allocating an array of Derived without new[]: Pointer to Base vtable is bad

Basically, I have a pure virtual class Base, and a concrete class Derived which inherits from Base. I then allocate a piece of memory and treat it as an array of Derived via a simple cast. Then, I populate the array using =. Finally, I loop through…
iano
  • 2,061
  • 1
  • 18
  • 22
0
votes
1 answer

How to look up vtable index of a method on the IWinHttpRequest interface?

I assume it's in winhttp.dll somewhere, but I can't find any reference to it by dumping the DLL using bindump. Anyone have any suggestions on how I can find the vtable index of a method?
Craig
  • 4,268
  • 4
  • 36
  • 53
0
votes
0 answers

What is this value in a vtable output from Clang?

Consider the following code: class base { public: base() = default; virtual int foo() { return 0; } }; class derived : public base { public: derived() = default; virtual int foo() { return 1;} }; Compiling this with Clang 3.3 I get…
Sam Cristall
  • 4,328
  • 17
  • 29
0
votes
1 answer

CLR implementation of virtual method calls via pointer to base class

I can not sleep until I know how occur recalling the desired virtual method by C#/CLR. In my book richter wrote no more no less than what CLR determine the actual type of the object and call the appropriate method. For example, in C + +, each…
Ark
  • 1,343
  • 2
  • 12
  • 26