I'm puzzled by this fragment of (C++14) code I wrote:
struct B {};
struct C { int m; };
struct D : B { int m; };
int main() {
C c = { 1 }; // this works
D d = { 1 }; // this doesn't work
}
I'm fine writing a constructor for D
myself, but I can't find a good explanation for why the struct D
is no longer initializable with an initializer list. All I changed was make it inherit from a completely empty class -- I suppose I somehow made it behave less struct-like.
How exactly does my compiler handle the structs C
and D
differently?