Regarding inheritence

Hi guys,
one simple question here.

When we create a class which derives from another class (let's say A extends B),
do we have to specify the inheritance in constructor in the implementation (i.e. *.cpp) of A ?

For example

a.cpp :

A() : B()
{
// constructor of A
}

or we can omit that part with the semi colon ( : B() ).

Thanks
You can omit it. You are simply calling the default constructor, which will be done anyway, even if you omit it.

Having said that, there is merit to using initializer lists to explicit initialize all data members, and I would extend that to include calling base class default constructors as well.
I see, if there is default constructor.

Thank you for the answer. :)
Last edited on
Topic archived. No new replies allowed.