Inheritance of constructors means just that. A derived class can implicitly inherit constructors from its base class (es).
The syntax is as follows:
struct B { B(int);
So now D has implicitly defined constructors:
D::D(int); // inherited D::D(string); // inherited
Ds members are by default constructed by these inherited constructors.
As if the constructors were defined as follows:
D::D(int x) : B(x) {} D::D(string s) : B(s) {}
A function is not something special. This is just an abbreviation to save the printed code of the template.
Here are the details of gory:
12.9 Inheritance of constructors
1) The use-declaration, which calls the constructor, implicitly declares a set of inheriting constructors. The set of candidates for inheritance of the constructors from class X specified in the using declaration, the actual constructors and conditional constructors that result from the conversion of the default parameters as follows:
- all constructors without patterns X and
- for each constructor without an X template, which has at least one parameter with a default argument, a set of constructors that excludes any specification of the ellipsis parameter and sequentially excludes the parameters with the default argument from the end of the type parameter list and
- all constructor templates X and
- for each X constructor template that has at least one parameter with a default argument, a set of constructor templates that results in omitting any specification of the ellipsis parameter and sequentially omitting the parameters with the default argument from the end of the Type parameter list
Andrew Tomazos Apr 02 '12 at 15:33 2012-04-02 15:33
source share