#Why doesn't this brace initialisation work?

11 messages · Page 1 of 1 (latest)

sturdy crane
#
struct Foo {};
struct Bar : Foo { int x; };

Bar bar = { 1 };

I get Initializer for aggregate with no elements requires explict braces and Missing field 'x' initializer from my linter on the final line.

If I remove Foo as a parent of Bar then these issues go away.

regal questBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

gaunt sequoia
#

Try Bar bar{{1}};

sturdy crane
#

The first error is replaced by Excess elements in struct initializer and the second remains

gaunt sequoia
#

Rip

sturdy crane
#

aha

#

Bar bar = { {}, 1 };

gaunt sequoia
#

Weird

sturdy crane
#

Seems it was added in cpp17

#

!solved