简体   繁体   中英

How can I dynamically allocate memories for 4-D array with 2-D fixed array in c++

How can I dynamically allocate memories for 4-D array with 2-D fixed array in c++

I know the way of assigning 3-D array with 2-D fixed array in this way

int n = 100;
double (*a)[4][5];
a = new double[n][4][5];

but in the 4-D case, what should I do?

int n = 100;
int m = 1000;
double (*(*a))[4][5];
a = new double[m][][4][5] ???

It is possible to avoid this problem by using quadruple pointer (double**** a), but I need fixed matrix ([4][5]) in my code system. please help

代替使用指针和跟踪内存,您应该使用向量。

vector<vector<vector<vector<int>>>> vector4d(dim1, vector<vector<vector<int>>>(dim2, vector<vector<int>>(4, vector<int>(5, 0))))

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