Am Thu, 14 Sep 2017 10:48:19 +0200
schrieb "Alf P. Steinbach" <
alf.p.stein...@gmail.com>:
> On 9/14/2017 10:18 AM, Ralf Goertz wrote:
> > Hi,
> >
> > why does brace initialization of a subclass of array fail and how
> > do I fix this?
> >
> >
> > #include <array>
> >
> > //typedef std::array<double,3> Space; //with this line it works
> > struct Space : public std::array<double,3>{};
> >
> > int main() {
> > Space x={{1,2,3}}; //fails when Space is subclass of array
> > return 0;
> > }
> >
>
> It's no longer an aggregate (simple class with no bases or
> user-provided constructors). List-initialization reduces to aggregate
> initialization when the class is an aggregate.
Hm, you mean to say it works with array because it doesn't have a
user-provided constructor so it reduces to aggregate initialization?
Which then fails in a subclass because it is no longer aggregate? But
the above program also fails to compile when I substitute array with
vector (but still works with the typedef). And vector does have
non-default constructors hence it is not aggregate. So why doesn't a
subclass of vector inherit its list-initialization constructors?