Single statement to create multidimensional array?

Hi,

I now have the following code:

1
2
3
4
5
6
7
8
9
10
11
12
bool **** done = new bool***[maxLocation->x];
                for(int o = 0; o < maxLocation->x; o++) {
                        done[o] = new bool**[maxLocation->y];
                        for(int j = 0; j < maxLocation->y; j++) {
                                done[o][j] = new bool*[maxLocation->z];
                                for(int u = 0; u < maxLocation->z; u++) {
                                        done[o][j][u] = new bool[N];
                                        for(int p = 0; p < N; p++)
                                                done[o][j][u][p] = false;
                                }
                        }
                }


Obviously this code is quite cumbersome since the entire array has static dimensions and all values are the same. I'm kinda expecting c++ to have an expression much like java that sais:
bool ****done = new bool[maxLocation->x][maxLocation->y][maxLocation->z][N];
that does the trick just the same... Likewise, I don't like deleting this static array. Isn't there a simple function like:
deleteMArray(done,new int[] {maxLocation->x,maxLocation->y,maxLocation->z,N}); where the given int array indicates the size of each dimension?

I mean, the code is easy enough to write myself, but it looks way too cumbersome and I can't believe there isn't a standard implemented for such a simple and frequently used structure...
closed account (S6k9GNh0)
Welcome to C++.
such a simple and frequently used structure...
o_O
Use std::vector
less performance... I don't want to use vectors.
closed account (S6k9GNh0)
The only thing I can suggest is you allocate enough space as you would for the multi-dimensional array then index it using math.
Topic archived. No new replies allowed.