Consider this struct:
struct S { int index; };
It can be initialized using the braced-list like so:
S s{10}; //s::index becomes 10
However if I specify a default value for a member:
struct S { int index = -1; };
The braced-list initialization gives me a compiler error that it cannot convert initializer list
to S
. I suspect it might have to do with the default constructors being generated for the struct because I have specified the default value. But why cannot the initializer list override that?
The reason I want this is that I want to either initialize the struct with values or default it to some "invalid" default values. Because of this restriction I have to either specify a constructor myself or initialize the "invalid" defaults explicitly every time.
I am using VS2015 compiler.