Tuesday 10 September 2013

Multidimensional array with initalizer list, omitting a size specification

Multidimensional array with initalizer list, omitting a size specification

I want to declare a multidimensional array containing n rows of 3 columns:
int array[][3] = {
{1,2,3},
{4,5,6}};
I'm compiling this with g++ 4.7.3, using --std=c++11.
It's not working, failing with the error:
test.cpp:6:16: error: too many initializers for 'int [0][3]'
This link seems to agree my syntax is correct, although the example given
there:
int anArray[][5] =
{
{ 1, 2, 3, 4, 5, },
{ 6, 7, 8, 9, 10, },
{ 11, 12, 13, 14, 15 }
};
also fails to compile.
What's wrong with my syntax? How do I declare an array with an initalizer
list, without specifying all dimension sizes?

No comments:

Post a Comment