need to create multiple dynamic arrays in c++ -


i need create number of arrays of object number need dependent on separate variable best way explain psudo code example:

int num = 4; for(int i=0;i<num;i++){    object_type arrayi [dynamic size]; } 

so need 4 arrays each names array0,array1,array2, , array3 , must dynamic arrays. there anyway in c++?

std::array<std::vector<object_type>, 4> array; (auto & v : array)     v.resize(dynamic_size); 

the names array[0], array[1], etc... instead of array1, array2, etc... cares? if absolutely must have names, cassio's answer best bet.

pre c++11 alternative:

std::vector<object_type> array[4]; (size_t i=0; i<4; ++i)     array[i].resize(dynamic_size); 

if want variable number of arrays, can use vector of vectors, , actually, initialization easier. doesn't require loop, can in constructor.

std::vector<std::vector<object_type>> array(num, std::vector<object_type>(dynamic_size)); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -