I can create a 2D array of size n*mby doing:
vector< vector< int > > foo(n, vector< int > (m)).
Suppose that at runtime I’m given a variable number of values,
e.g. v_1, v_2, v_3, ..., v_k and want to create the following:
vector< vector< ... vector< int > ... > > foo(v_1, vector< ... > (v_2, vector< ... > ..));
In other words create a multidimensional array of size v_1* v_2 * v_3 ... *v_k. How can I do this? Is this possible?
You can’t do this – data type must be set at compile time. That said, it’s quite practical to use a single array with the correct total number of elements, and create a mapping so that your logical
[i1][i2][...]is found at say[i1*v2*v3...vk + i2*v3..vk + ...].