Search code examples
c++default-constructorvtablevptr

Concept of vptr and vtable in C++


Why only default constructor only able to create vptr(Virtual Table Pointer) and vtable(Virtual Table)? Why parameter constructor not able to


Solution

  • First, vtables and vptrs are not specified by the C++ language standard.

    They're an implementation detail, although as far as I know all extant C++ implementation use that technique to implement virtual function dispatch.

    With such an implementation, all constructors for a class with virtual member functions, necessarily establish the object's vptr. Things wouldn't work without it. So …

    Why parameter constructor not able to

    … is simply an incorrect assumption.