VTable structure used by the compiler to keep track of the virtual functions associated with a class.There is one instance of a VTable for every class containing virtual functions. All instances of a given class point to the same VTable.

The C++ compiler inserts an extra pointer to a vtable which will keep a function pointer to the virtual function that should be called.

The VTable pointer in the base class points to an array of VTables. The number of entries in the array of VTables depends upon the number of virtual functions in the class.

Note that a pure virtual function maps to function that will result in an exception.

Constructor representation in C

In C++, objects may be allocated on the heap or the stack. This has implications in the mapping from a C++ constructor to an initialization function in C.

A::A(int x)
{
m_x = x;
m_z = 0;
}

The mapped constructor takes an additional this pointer. A NULL is passed as the this pointer when the object has to be allocated on the heap. A valid stack address is passed when an object is on the stack.

If a NULL pointer is passed to the construction function, it allocates memory before performing the initialization.