Default constructor assumption scenarios in C++:

In general, most documentations state or claim that there is a default constructor assumed
by the compiler for a class in-case we do not happen to provide one, and it stops there.
With this claim there is a general belief by the C++ community that this is true for every given
class in the code for which they do not provide any constructors at all.
This is a wrong assumption, and the claim by most C++ documentations is factually in-
correct.
Let us dive in to prove this point. A default constructor assumption by the compiler for a
class not defined with any constructor by the programmer is only in the following context’s:
Around 4 different scenarios in Traditional C++ [98-2003] standards and one specific
scenario in modern C++.
So, what are the 4 + 1 scenarios where a compiler would assume a default constructor in
C++?

Scenario-1: Consider the following example code.

If the base class is provided with our own default constructor and the derived class has not
been defined with a default constructor, then the compiler would assume for the derived.


Note: If in-case the base class does not have a default constructor defined, then the
compiler would not assume a default constructor for the base class nor for the derived class.

By generating the assembly listing of the above example, we can analyse the same.

Try commenting out the base class constructor definition and re-generate the assembly
listing, you will never find the decorated name entries of the constructors.

Scenario-2:
If a container class contains an object of a class having a default constructor defined, then
the compiler would assume for the container class as well.
Note: If in-case the contained object belongs to class not having a default constructor, then
the compiler would not assume any default constructor for the contained class nor the
container class.
Consider the following example code:

Assembly listing of the above example:

Scenario-3:
In the case of virtual (hybrid) inheritance model.
Given the following example, the classes ‘CB’ and ‘CC’ virtual inherit ‘CA’ base class, if we
have not defined any constructors for these classes, the compiler would start assuming a
default constructor for the derived ‘CB’, ‘CC’ and further down for other derived classes in the
inheritance hierarchy.
Consider the following example:

The assembly listing of the above example illustrates the compiler assumed default
constructors for the all the derived classes.


Scenario-4:
If a class is polymorphic, that is the class comprises of one or more virtual member
functions, and for such a class no default constructor has been provided, then the compiler
would assume one for the said class.
The compiler generated default constructor would hold instructions induced by the compiler
to initialize the ‘vfptr’ element (an invisible data member of the class – assumed by the
compiler) to point to the VFTABLE (virtual function table).

The assembly listing of the example illustrates or proves the same.

Scenario-5:
If we go in for in-class initialization, A C++11 class feature. When we do not happen to
provide any constructors for a class using this feature, then the compiler would assume a
default constructor.

The Assembly listing proves the point, the compiler has indeed assumed a default
constructor.