In this piece of code the initialisation of the Foo
does not compile, I get the error error: too many initializers for 'std::array<std::array<int, 3>, 3>
.
On the other hand the initialisations of FooOK
, FooOK1D
and Bar
compile fine.
#include <array>
#include <vector>
std::array<std::array<int, 3>, 3> Foo
{
{1,2,3}, // does not compile: error: too many initializers for 'std::array<std::array<int, 3>, 3>'
{4,5,6},
{7,8,9}
};
std::array<std::array<int, 3>, 3> FooOK
{
1,2,3 // compiles fine
};
std::array<int, 3> FooOK1D
{
1,2,3 // compiles fine
};
std::vector<std::vector<int>> Bar
{
{1,2,3}, // compiles fine
{4,5,6},
{7,8,9}
};
What is the problem here?