Go Down

Topic: Nested Array errors (Read 946 times) previous topic - next topic

So I am trying to create a dynamic array that has arrays in it.

My code:
int mines1[4] = {0,1,2,3};
int mines2[4]= {4,5,6,7};
int mines3[4]= {8,9,10,11};
int mines4[4]= {12,13,14,15};
int mines5[4]= {16,17,18,19};
int mines6[4]= {20,21,22,23};
int mines7[4]= {24,25,26,27};
int mines8[4]= {28,29,30,31};
int mines9[4]= {32,33,34,35};
int mines10[4]= {37,38,39,40};
int mines11[4]= {41,42,43,44};

int mine_field[11][4] = {{mines1},{mines2},{mines3},{mines4},{mines5},{mines6},{mines7},{mines8},{mines9},{mines10},{mines11}};

My problem is that with this code I get the error "error: invalid conversion from 'int*' to 'int'" and if i remove the [11][4] and use just [] next to mine_field it gives me "error: braces around scalar initializer for type 'int'". I come from python and am stumped about why this wont work, any and all help is greatly appreciated.

pYro_65

#1
Nov 07, 2012, 03:51 am Last Edit: Nov 07, 2012, 04:00 am by pYro_65 Reason: 1
You could use an array of pointers,
Code: [Select]
int *mine_field[11] = {mines1,mines2};

Or put values directly in,
Code: [Select]
int mine_field[11][4] = {{0,1,2,3},{4,5,6,7}};

I only put the first two entries in, just fill in the rest.

Go Up