我有些困惑于动态分配3D数组。目前,我只是像这样分配一个大的内存块:
int height = 10;
int depth = 20;
int width = 5;
int* arr;
arr = new int[height * width * depth];
现在,我想要更改3D数组中的一个值,比如说:
//arr[depth][width][height]
arr[6][3][7] = 4;
然而,我不能使用上述代码来改变值。我如何使用单个索引访问深度=6、宽度=3、高度=7处的元素?
arr[?] = 4;
有没有更好的方法动态分配一个三维数组?