[英]Indexing into std::array of std::array
I have some confusion about indexing of an array of arrays in C++: 我对在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. 因此,使用outer_index
进入数组的SIZE_OUTER
首先出现,然后进入内部索引。
Is that true? 真的吗?
Yes. 是。 Think like this: arr[o]
accesses the o-th element of arr
. 认为是这样的: arr[o]
访问的邻个元素arr
。 The fact that the element is an array too doesn't change much. 元素也是数组的事实并没有太大改变。
Subsequent calls to operator []
access elements returned by previous calls. 对operator []
后续调用将访问先前调用返回的元素。
Yes. 是。 Let break it down a little 让我们分解一下
array<int, SIZE_INNER>
Is going to create an array of size SIZE_INNER. 将创建一个大小为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. 使用[]
运算符时,最右边的是最里面的数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.