• Create Account

## Array in array, how to fill with content?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #193i  Members

117
Like
0Likes
Like

Posted 14 August 2012 - 04:18 AM

Hi, i want to use a array in array, but none of the ways in the docs seem to work for me:

For example:
array<array<int>> arr;
arr[0] = {0};


gets me a:

ERR : Expected expression value

I tried other ways, like arr[0].insertLast(0); or even arr.resize(1); arr[0]...; none seems to work.

How is it supposed to work?

### #2saejox  Members

714
Like
1Likes
Like

Posted 14 August 2012 - 08:49 AM

these all work.
  array<array<int>> arr;
arr.resize(10);
arr[0].resize(10);
arr[0].insertLast(0);
arr[0][0] = 52;


### #3Andreas Jonsson  Moderators

4443
Like
1Likes
Like

Posted 14 August 2012 - 10:01 AM

The initialization list can only be used in variable declarations, i.e. you can't use it in ordinary assignment expressions like a[0] = {0}.

You have to remember that an array of arrays is just that, an array of arrays. The elements in the first array are all individual arrays of the defined element type. A change on one of the subarrays doesn't automatically reflect on the other subarrays.

array<array<int>> arr1 = {{0,0}, {1,1}}; // a 2 by 2 array, fully initialized

array<array<int>> arr2(2); // a 2 by 0 array
arr2[0] = array<int>(2, 0);  // first row is now 0, 0
arr2[1] = array<int>(2, 1);  // second row is now 1, 1

array<array<int>> arr3(2, array<int>(2, 0)); // a 2 by 2 array. all elements are 0
arr3[1] = array<int>(2, 1); // fully initialized

array<array<int>> arr4; // a 0 by 0 array
arr4.resize(2);             // a 2 by 0 array
arr4[0].resize(2);
arr4[1].resize(2);         // a 2 by 2 array
arr4[0][0] = 0;
arr4[0][1] = 0;
arr4[1][0] = 1;
arr4[1][1] = 1;             // fully initialized


All four of these produce the same result, a 2x2 array where the first row is 0,0, and the second row is 1,1.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

### #493i  Members

117
Like
0Likes
Like

Posted 14 August 2012 - 09:56 PM

Thanx

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.