Pages: [1]   Go Down
Author Topic: Nested Array errors  (Read 827 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

North Queensland, Australia
Offline Offline
Edison Member
Karma: 65
Posts: 2107
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could use an array of pointers,
int *mine_field[11] = {mines1,mines2};

Or put values directly in,
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.
« Last Edit: November 06, 2012, 10:00:43 pm by pYro_65 » Logged

Pages: [1]   Go Up
Jump to: