mardi 27 octobre 2015

{} vs. () initialization of a class member

I do not understand why the following code compiles ?

struct A{ A(int); }; struct B{ A a{1}; };

but this does not:

struct A{ A(int); }; struct B{ A a(1); };

error: expected ',' or '...' before numeric constant

Is there some reason the compiler does not accept the second form? I am aware of the most vexing parse ambiguiy, but I do not think this question is related.

I tried this on gcc-5.1.0 with --std=c++11

Aucun commentaire:

Enregistrer un commentaire