This thread in SO is about multidimensional array in c++.
I have to port some code from c# to cpp. i have code like this:
private double[,] B;
...
this.B = new double[states, symbols];
double[][, ,] epsilon = new double[N][, ,];
double[][,] gamma = new double[N][,];
...
s += gamma[i][t, k] = ...
i have thought to use plain double array of array but it's quite pain. another solution could be vector of vector of double, or a custom Matrix2D and Matrix3D classes?
what is the best way for each of those cases?
WHAT I LEARNED:
multidimensional array in c++ is a great topic, and internet is full of resources. it could be handled in various ways, some of them really tricky, some others more faster to write.
i think that the best way is to deal with it is to use some libraries that takes in account this topic. there are a lot of them: Armadillo (nice MATLAB syntax conversion), Eigen i think is one of the better one, easy to install, easy to use, powerfull. Boost::multi_array is anotherone, and Boost is really a famous lib that is important just to take a look at how it handle the topic. As Konrad Rudolph answer STD with nested vectors or this could be another solution but, after a little search, i think the less elegant even the more easy and fast to code without external libs.
write a custom class. mayebe such a good exercice. peter answer or this or this are a good start point and also this post is interesting but expecially this great post blog from martin moene (one of the best essay on this topic i've read today). I mention also this answer for sparse array.
here is a nice tutorial direct from stroustrup
have a nice time with multidimensional array :-)