ibm123
ibm123

Reputation: 1254

c++ int array with values of 2 dimension int array (3d array)

I'm trying to make an array which contain int[][] items

i.e

int version0Indexes[][4] = { {1,2,3,4}, {5,6,7,8} };
int version1Indexes[][4] = { ...... };

int version15Indexes[][4] = { ... };

(total of 16)

int indexes[][][] = { version0Indexes,version1Indexes, .. };

anyone can suggest how to do so ?

Thanks

Upvotes: 1

Views: 79

Answers (2)

lodo
lodo

Reputation: 2383

Either you inline your arrays inside indexes:

int indexes[][2][4] = {
    { { 1, 2, 3, 4}, {5, 6, 7, 8} },
    { {....}, {....} }
    ....
}

Or you make indexes an array of pointers:

int (*indexes[])[4] = { version0Indexes, version1Indexes, .... };

What you wrote in your question is not directly possible because, when used, an array variable is actually a pointer (that's why indices has to be an array of pointers).

Upvotes: 2

Wintermute
Wintermute

Reputation: 44023

You can use an array of pointers to array:

int (*indexes[])[4] = { version0Indexes, version1Indexes, .. };

Upvotes: 2

Related Questions