简体   繁体   中英

Indexing into std::array of std::array

I have some confusion about indexing of an array of arrays in C++:

I have:

array<array<int, SIZE_INNER>, SIZE_OUTER> arr;

When I do indexing, I assume the following:

arr[outer_index][inner_index]

So, outer_index into the array with SIZE_OUTER comes first, and the inner index then comes second.

Is that true?

Yes. Think like this: arr[o] accesses the o-th element of arr . The fact that the element is an array too doesn't change much.

Subsequent calls to operator [] access elements returned by previous calls.

Yes. Let break it down a little

array<int, SIZE_INNER>

Is going to create an array of size SIZE_INNER. Now you wrap that array in

array<array<int, SIZE_INNER>, SIZE_OUTER> arr;

So the inner array is your "column" and the outer array is your "row". Just like with plain 2d arrays.

When working with the [] operator the one farthest to the right is for the inner most array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM