How to resize a multidimensional vector, for example:
vector <vector <vector <custom_type> > > array;
For example, do I need an array [3] [5] [10]?
You must resize all nested vector one by one. Use nested for loops or recursion.
vector
for
array.resize(3,vector<vector<custom_type> >(5,vector<custom_type>(10)));
see also Boost.MultiArray
Boost.MultiArray provides a generic N-dimensional array concept definition and common implementations of that interface.
I did it))
array.resize(3); for (int i = 0; i < 3; i++) { array[i].resize(5); for (int j = 0; j < 5; j++) { array[i][j].resize(10); } }
I would make a custom container containing a vector of vectors (from ... for a dimension) and resize using the size options for each dimension. Thus, you can place an invariant of equal size on a dimension in one place. Actual resizing can be done in a loop according to the measurement.There will be a little work related to publishing what you need to access (operator [], ...)