Q:

Unexpected size for virtual tables

I'm studing C++ inheritance and so I wrote this code:
// 08 Diamond Inheritance 02.cpp : Defines the entry point for the console application.
//   I'm using Microsoft Visual Studio 2015

#include <iostream>

using namespace std;

class SuperVirtual
{
public:
    int sv;
    SuperVirtual(int p1 = 11) : sv(p1)
    {
        cout << "\n SuperVirtual ctor for &" << this;
    }

    virtual void methodSuperVirtual_01()
    {
        cout << "\n Inside SuperVirtual::methodSuperVirtual_01(): sv = " << ++sv;
    }

    virtual void methodSuperVirtual_02()
    {
        cout << "\n Inside SuperVirtual::methodSuperVirtual_02(): sv = " << ++sv;
    }
};

//---------------------------------- 
class DerivedSV_01 : public SuperVirtual
{
public:
    int dsv;
    DerivedSV_01(int p1 = 21) : dsv(p1)
    {
        cout << "\n DerivedSV_01 ctor for &" << this;
    }
    virtual void methodSuperVirtual_01() override
    {
        cout << "\n Inside DerivedSV_01::methodSuperVirtual_01()";
    }
    //----------------------------------------------------
    virtual void onlyForDerivedSV_01()
    {
        cout << "\n Inside DerivedSV_01::onlyForDerivedSV_01()";
    }
};

int main()
{
    SuperVirtual sv1(1);
    sv1.methodSuperVirtual_01();

    DerivedSV_01 dsv_01;
    dsv_01.methodSuperVirtual_01();
    dsv_01.onlyForDerivedSV_01();

    return 0;
}

I had read that:

Whenever a class itself contains virtual functions or overrides virtual functions from a parent class the compiler builds a vtable for that class. The vtable contains function pointers that point to the virtual functions in that class. There can only be one vtable per class, and all objects of the same class will share the same vtable.

At this point, I supposed that the virtual table of class SuperVirtual contains 2 elements, while the virtual table for class DerivedSV_01 contains 3 elements: 2 for inherited (and eventually ovverridden) methods + 1 for the new virtual method onlyForDerivedSV_01().
However, inspecting the objects created in main() with the Visual Studio Debugger, I found that:

virtual table for instance of class SuperVirtual contains 2 elements (OK !)
virtual table for instance of class DerivedSV_01 contains 2 elements (Why ?)

For completeness of information, I provide the following screenshot:

A:

I can reproduce this with exactly your code in VS2019 when compiling in debug mode (compiler optimization turned off). I am quite sure this is only a display issue in the debugger window.

Please note that the __vfptr array is only displayed under SuperVirtual, not directly under dsv_01, so of course the debugger only knows about the functions in a SuperVirtual vtable.
But if you look at the Value column for the __vfptr, you'll notice that in SuperVirtual::'vftable'[3] and DerivedSV_01::'vftable[4]' (both marked green) different array sizes are given.
Let's take a look at the memory at the vftables (the addresses of the vftables can be seen at the start of the Value column for the __vfptr entries and are marked orange and red).

You'll notice that SuperVirtual::'vftable'[3] has two function pointers (marked brown) and a nullptr. DerivedSV_01::'vftable[4]' has three pointers (marked purple and blue) and a nullptr. The debugger window tells us what the first two entries are (also marked purple), but take a look at the third entry in the watch window (marked blue).

The debugger says that the third entry is the DerivedSV_01::onlyForDerivedSV_01. That totally matches your (and my) expectations.

