Why does inheriting constructors from a base class break aggregate initialization?
For example, this works:
struct MyArray : std::array<int, 2ul> {};
MyArray a{1, 2};
but this doesn't work:
struct MyArray : std::array<int, 2ul>
{
using std::array<int, 2ul>::array;
};
MyArray a{1, 2};
Since C++17, aggregates can have base classes, so that for such structures being derived from other classes/structures list initialization is allowed:
struct MoreData : Data {
bool done;
};
MoreData y{{"test1", 6.778}, false};
In C++17 an aggregate is defined as
For more details you can refer to Chapter 4 Aggregate Extensions from C++17 - The Complete Guide By Nicolai M. Josuttis
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With