How to resize multidimensional vector such as:
vector > > array;
For example, I need arr
You should resize all the nested vector
s one by one. Use nested for
loops or recursion.
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);
}
}
see also Boost.MultiArray
Boost.MultiArray provides a generic N-dimensional array concept definition and common implementations of that interface.
array.resize(3,vector<vector<custom_type> >(5,vector<custom_type>(10)));
I would make a custom container containing a vector of vectors (of ... per dimension) and resize with resize-functions per dimension. This way you can put the invariant of equal size per dimension in one place. The actual resizing can then be done in a loop according to dimension.
There will be a bit of work involved in making public what needs to be accessed (operator[],...)