简体   繁体   English

声明多维std :: arrays

[英]Declarring multidimensional std::arrays

This is the first time that I am going to use a multidimensional std::array. 这是我第一次使用多维std :: array。 I want to declare 9 matrix of 3 x 3 dimensions. 我想声明9个3 x 3尺寸的矩阵。

In a conventional c++ array we declare like the following. 在常规的c ++数组中,我们声明如下。

int a[9][3][3]; int a [9] [3] [3];

When I try to declare this array using std::array the sequence of dimensions is upside down, It must be declared like the following. 当我尝试使用std :: array声明此数组时,维数序列颠倒了,必须像下面这样声明。

array<array<array<int, 3>, 3, 9)

my expectation was to declare that matrix like we declare the conventional arrays like the following. 我的期望是像我们声明常规数组一样声明该矩阵,如下所示。

  array<array<array<int, 9>, 3, 3)

There is no documentation on this matter. 没有关于此问题的文档。 What is the C++ standard 什么是C ++标准

Use > instead of ) : 使用>代替)

using matrices = array<array<array<int,3>,3>,9>;

And you can write, as suggested in the comments: 您可以按照评论中的建议进行编写:

// N is number of rows, M number of columns
template<int N, int M>
using matrix = array<array<int,N>,M>;

using matrices = array<matrix<3,3>,9>;

Check out Why can't simple initialize (with braces) 2D std::array? 签出为什么不能简单地用花括号初始化2D std :: array?

Try std::array<std::array<std::array<int, 3>, 3>, 9> myArray; 尝试std::array<std::array<std::array<int, 3>, 3>, 9> myArray; .

Remember to #include<array> . 记住要#include<array>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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