Variable length arrays didn't make it in the latest C++ standard. You can use std::vector
instead
std::vector<std::vector<double> > arr;
Or, to fix for example the second dimension (to 10 in this example), you can do
std::vector<std::array<double, 10> > arr1; // to declare a fixed second dimension
Otherwise you need to use old pointers,
double (*arr)[10]; // pointer to array-of-10-doubles
In light of @Chiel's comment, to increase performance you can do
typedef double (POD_arr)[10];
std::vector<POD_arr> arr;
In this way, you have all data stored contiguously in the memory, so access should be as fast as using a plain old C
array.
PS: it seems that the last declaration is against the standard, since as @juanchopanza mentioned, POD arrays do not satisfy the requirements for data to be stored in an STL array (they are not assignable). However, g++
compiles the above 2 declarations without any problems, and can use them in the program. But clang++
fails though.