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

C++ polymorphism not working with ESP-IDF

I have an abstract class namespace AComp { class A { public: virtual void func() = 0; virtual ~A(); }; A::~A() { } } I also have an abstract sub-class which does not provide implementation for the pure virtual…
-1
votes
0 answers

c++ Why virtual template functions are not allowed

In c++, it is not possible to create virtual template functions. Reason as I understand is that, we cannot create a base class with the virtual table with infinite number of matching functions. What I want to clarify is, whether this is a limitation…
De Abrew
  • 21
  • 3
-1
votes
1 answer

Do Rust fat pointers consume less memory than thin pointer within vectors?

I was reading this Reddit comment which compares thin and fat pointers. To be specific, the downsides of thin pointers within vectors: User A heap allocates each object individually and takes many thin pointers to them. For user A thin pointers are…
-1
votes
1 answer

Is there a way to decrease the size of the object by removing "vptr"

I have a code like this using CRTP and C++20: template class Base { public: void m() { static_cast(this)->feature(); } virtual constexpr void feature() = 0; } class BaseImpl: public…
-1
votes
2 answers

What does .word 0 mean in ARM assembly?

I'm writing a C++ state machine for Cortex-M4. I use ARM GCC 11.2.1 (none). I'm making a comparison between C and C++ output assembly. I have the following C++ code godbolt link struct State { virtual void entry(void) = 0; virtual void…
-1
votes
2 answers

Calling overriden (derived class) version of a non-virtual base class function from inside base class?

So, if I have class base { public: virtual void start(); virtual void stop(); void doSomething() { start(); .... stop(); } } class derived : public base { public: void start(); void stop(); } calling derived.doSomething() will…
-1
votes
1 answer

Undefined reference to vtable for class despite no virtual function

I'm practicing with QT for one of my classes, and I keep getting Undefined reference to vtable for class despite no virtual function. I've looked around for a solution but it seems like they all had at least one function that is declared as virtual.…
qwerty_99
  • 640
  • 5
  • 20
-1
votes
1 answer

Error connecting Worker Thread signal with MainWindow slot (Qt5)

I want to write a simple Application which launches a thread to do some computations. The worker thread should periodically send signals to the MainWindow to inform it about the current state of progress. In order to implement the worker thread, I…
Mantabit
  • 269
  • 1
  • 4
  • 14
-1
votes
1 answer

How does Java (or C++) handles invocation of methods defined in interfaces

I am currently working on my programming language and it will have only interfaces and no object inheritance. And I have an issue, because I don't know how to make a vtable so an appropriate method could be called in a class with many interfaces…
Arthur
  • 23
  • 2
-1
votes
1 answer

MI function definition in one base class not sufficient for virtual function of another base class

I have a derived class inheriting from both an interface and a base class. The interface defines a virtual function GetId, which is implemented in the other base class. class ITestClient { public: virtual int GetId() = 0; }; class…
-1
votes
2 answers

Undefined reference to vtable error

I have been trying to sort out this error for 3 hours now, and I have still not found anything wrong with my code. I have a class GrainLJ which inherits from an abstract class Grain. The class GrainLJ also has 2 subclasses GrainLJT1 and GrainLJT2.…
Ruslan Mushkaev
  • 1,005
  • 1
  • 7
  • 10
-1
votes
6 answers

QAbstractTableModel inheritance vtable problem

Here's another problem with qt: I extend a QAbstractTableModel, but I get a compiling error ( I'm using cmake) // file.h #ifndef TABLEMODEL_H #define TABLEMODEL_H #include class TableModel : public…
JuanDeLosMuertos
  • 4,532
  • 15
  • 55
  • 87
-1
votes
1 answer

How a single vtable is tracking new virtual functions?

I'm using VS 2013 and trying to see how vptr and vftable are working at object level. So I have the following classes: #include using namespace std; class baseClass { public: void nonVirtualFunc() {} virtual void…
madu
  • 5,232
  • 14
  • 56
  • 96
-1
votes
3 answers

Is virtual table necessary for C++?

I have a doubt about C++ virtual table recently. Why does C++ use virtual table? =>Because C++ compiler does not know the actual function address --->Why? =>Because C++ compiler does not know the exact type(Cat? Dog? Animal?) of the object the…
Guocheng
  • 543
  • 3
  • 15
-1
votes
2 answers

Virtual ptrs and class size

What will be size of a derived class which inherited from 3 base classes and all are empty? class derived also empty base1 base2 base 3 at base classes at same level and derived class inherited from all three inheritance is public inheritance is…