{} 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 is not so:

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

error: expected ',' or '...' before a numerical constant

Is there a reason the compiler does not take the second form? I know about the most annoying parsing, but I don't think this question is related.

EDIT: As Bo explains in the comments below, I was wrong. Question associated with annoying analysis.

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

+4
source share
1 answer

​​ , , , --, ( ).

brace-or-equal-initializer ( ++ 11 ++ 14, Chris , ++ 1z ).

+10

Source: https://habr.com/ru/post/1613415/


All Articles