I am confused with the following statement.
From the specification:
Before the implicitly-declared default constructor for a class is
implicitly defined, all the implictly-declared default constructors
for its base classes and its non static data members shall have been
implicitly defined.
What i understand is :
implicitly declared default constructor is implicitly defined when the
object is created.
What does the above statement means?. if base class contains explicit default constructor, then the derived class can not have a implicit default constructor?. Kindly clarify, it could be nice if someone provides piece of sample code.
Assume you have classes
BaseandDerived(which is derived from base).Let’s assume both of them have implicitly declared default constructors. When you will create an object of
Derivedclass, the following will happen. First, implicitly-declared default constructor for theBaseclass will be defined. After that, the same will happen with the implicitly-declared constructor for theDerivedclass.This totally makes sense, because when you create the object of
Derivedclass, the constructor for theBaseclass gets called first. If it will not be defined by that time, well, something bad will probably happen.The same things apply to any class members that have such constructors: those are defined before the class’ own constructor will get defined.