The made-for solution here is std::vector
. It allocates memory on the heap, which is much larger than the stack, and can change its size without much extra effort at all.
typedef std::vector<float> vec;
typedef std::vector<vec> vec2D;
typedef std::vector<vec2D> vec3D;
typedef std::vector<vec3D> vec4D;
typedef std::vector<vec4D> vec5D;
vec5D d (15, vec4D (15, vec3D (15, vec2D (15, vec (15)))));
//use as you would a normal array for the most part
Of course having a 5D array (as mentioned "needed" in the comments) isn't something you particularly want. I recommend you make a Matrix
class of sorts that has an underlying 1D vector instead.
Even better, rethink your design. There's rarely a time when you actually do need a highly multidimensional array such as that one.