This is a follow up question to Is this reference-initialization or aggregate-initialization?
Consider the same example:
struct A {};
struct B : A{};
A a{ B() };
Does this is an aggregate initialization or reference initialization?
I mean by "reference-initialization" that the implicity-declared copy constructor A::A(const A&) is used where the reference parameter is bound to A subobject of the initializer expression B().
Also why this is not an aggregate initialization even though the class A is an aggregate class?
Ais an aggregate andA a{ B() }is list initialization according to the following rule(s):(emphasis mine)
Note in the above, we do not reach bullet 3 as bullet 1 is satisfied and so used.
This means that the object
Ais initialized from the single elementB()using direct-initialization. This in turn means that the copy constructorA::A(const A&)will be used.Here, the parameter
const A&of the copy ctorA::A(const A&)can be bound to aBobject so this works without any problem.Because to do aggregate initialization bullet 3 here should be reached and satisfied but we never reach bullet 3 because bullet 1 is satisfied.