I have this example
struct B { B(); };
struct D : B { };
D d{ B() }; // what happens here? or why it's well-formed
This is an aggregate initialization, but I can't understand how d
is constructed? Does the compiler generates implicitly a copy constructor with this signature D::D(const D&)
or D::D(const B&)
or what? It's clear that the compiler does not generate D::D(const D&)
because const D& = B()
is ill-formed. So this means it generates a copy constructor D::D(const B&)
?
Now what would happen if I inherits constructors from B
:
struct B { B(); };
struct D : B { using B::B; };
D d{ B() }; // why it's ill-formed?
One said to me that the default copy constructor of B
which is B::B(const B&)
is inherited into D
but it's excluded from the set of candidates, that's why it's ill-formed. Is that true?
D
, but then you talk about copy constructors as though one is. The answer is that it's aggregate initialization. – Seamaid