Understanding virtual base classes and constructor calls

There is always just one constructor call, and always of the actual, concrete class that you instantiate. It is your responsibility to endow each derived class with a constructor which calls the base classes’ constructors if and as necessary, as you did in B‘s constructor.

Update: Sorry for missing your main point! Thanks to ildjarn.

However, your B inherits virtually from A. According to the standard (10.1.4 in the FIDS), “for each distinct baseclass that is specified virtual, the most derived object shall contain a single base class subobject of that type”. In your case this means that when constructing the base, your class F immediately calls A‘s default constructor, not B‘s.

Leave a Comment