Consider the following declaration:
#include <array>
struct X
{
//std::array<bool,3> arr={false,false,false};
bool brr[3]={false,false,false};
};
As is, it compiles normally by g++ 5.2. But if I uncomment the std::array
, I get an error:
test.cpp:5:46: error: array must be initialized with a brace-enclosed initializer
std::array<bool,3> arr={false,false,false};
^
test.cpp:5:46: error: too many initializers for ‘std::array<bool, 3u>’
OTOH, this declaration works without problems inside main()
. Also, the following initialization does work inside struct X
:
std::array<bool,3> arr={{false,false,false}};
Why can't I use the simple initialization with single braces in struct definition?
See Question&Answers more detail:os