The number of vptrs are often required for a object whose clas( child ) has single inheritance having a base class which multiple gets base1 and base2. What's the technique for determining the number of vptrs a object provides it's handful of single inheritance and multiple inheritance. Though standard does not specify about vptrs but Among the finest to understand how an implementation does virtual function implementation.

So why do you care? The easy response is enough, however i guess you would like some thing complete.

This isn't area of the standard, so any implementation is free of charge to complete what ever they want, but an over-all guideline is the fact that within an implementation that utilizes virtual table pointers, like a zeroth approximation, for that dynamic dispatch you'll need a minimum of as numerous pointers to virtual tables as you will find classes that add a brand new virtual approach to the hierarchy.

// some examples:
struct a { void foo(); };           // no need for virtual table
struct b : a { virtual foo1(); };   // need vtable, and vptr
struct c : b { void bar(); };       // no extra virtual table, 1 vptr (b) suffices
struct d : b { virtual bar(); };    // extra vtable, need b.vptr and d.vptr

struct e : d, b {};                 // 3 vptr, 2 for the d subobject and one for
                                    // the additional b
struct f : virtual b {};
struct g : virtual b {};
struct h : f, g {};                 // single vptr, only b needs vtable and
                                    // there is a single b

Essentially each subobject of the type that needs its very own dynamic dispatch (cannot directly reuse the mother and father) would want its very own virtual table and vptr.

Observe that compilers could do any kind of chicanery there, as lengthy because the different subobjects have a similar memory footprint because the original class. That's, by fixing the this pointer of the type to the of their bases, the memory pointed has got the same footprint being an object of this particular base type.