Variable-length arrays did not 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 (up to 10 in this example), you can do
std::vector<std::array<double, 10> > arr1;
Otherwise, you need to use the old pointers,
double (*arr)[10];
In the light of @Chiel's comment, to improve performance, you can do
typedef double (POD_arr)[10]; std::vector<POD_arr> arr;
That way you have all the data stored in memory in memory, so access should be as fast as when using the plain old C array.
PS: the last declaration seems to be contrary to the standard because, as mentioned by @juanchopanza, POD arrays do not satisfy the requirements for storing data in an STL array (they cannot be assigned). However, g++ compile the above 2 declarations without any problems and can use them in the program. But clang++ fails.
vsoftco
source share