Let say we have below program:
class A
{ public:
virtual fun(){};
};
class B:public A
{ public:
virtual fun(){};
};
int main()
{
A a1
Note that this is strictly implementation dependent.
C++ Standard does not talk of vptr
or vtable
, the virtual mechanism is left out as an implementation detail for compilers. So practically, compilers can implement it without using vptr
or vtable
.However, almost all known compilers implement it using vptr
and vtable
.
Given the above, to answer your question:
Each class will have its own virtual table.
While each object has its own virtual pointer.