You are here:

C++/constructors in c++

Advertisement


Question
Hi sir !why can not we inherit constructors in c++?
i have read so many books.but i can not understand.
can you please explain clearly?

Answer
The earlier standard for C++ (C++98) did not allow constructors to be inherited.

"In C++98, we can "lift" a set of overloaded functions from a base class into a derived class ... Little more than a historical accident prevents using this to work for a constructor as well as for an ordinary member function." - Stroustrup

The current C++ standard (C++11) provides the facility to explicitly inherit constructors from a base class.
http://www.stroustrup.com/C++11FAQ.html#inheriting
http://en.wikipedia.org/wiki/C%2B%2B11#Object_construction_improvement

This must be used with care, though, if a derived class defines new non-static member variables requiring initialization.  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.

Experience

about 15 years or so

Education/Credentials
post graduate engineer

©2016 About.com. All rights reserved.