C++11: Inheriting Base Class Constructors


Sometimes a derived class’s constructors simply mimic the base class’s constructors. A frequently requested convenience feature for C++11 was the ability to inherit a base class’s constructors. You can now do this by explicitly including a using declaration of the form

using BaseClass::BaseClass;

anywhere in the derived-class definition. In the preceding declaration, BaseClass is the base class’s name. With a few exceptions (listed below), for each constructor in the base class, the compiler generates a derived-class constructor that calls the corresponding base-class constructor. The generated constructors ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.