multidimentional vector

mikledet

New member
multidimentional vector

Sorry for the English - I dont have hebrew on this PC... I have a need for a two dimentional array, but with dinamical length (run time). At the moment the code is like that: g_RGBtoHSV[0]=new int[colors]; g_RGBtoHSV[1]=new int[colors]; As you can see - 'colors' is a parameter - the run time dinamicaly size for the arrays. How ever, I would prefer to use a container class if possible, for better security. I know that I can have a two dimentional vector so: vector < vector<int> > g_RGBtoHSV; But how can I determine the size of the vectors? Thanks in advance.​
 

mikledet

New member
to clearefy

for example: vector <vector <int> > v; /*two dimensions*/ v.push_back(vector <int>()); /*create v[0]*/ v.push_back(vector <int>()); /*create v[1]*/ v[0].push_back(15); /*assign v[0][0]*/ v[1].push_back(16); /*assign v[1][0]*/ This ok, when I am "push_back"ing, but how do I limit the size of the dimentions to X, and, how do I asign v[0][150] directly? I know I can: v[0][150]= value However this is possible only if the 150'th element is already allocated... - which brings me back to how do I allocate such a vector as above to for exaple 150 elements legth (for each dimention)? Hope this was better understood then the above post... Thanks.​
 

mikledet

New member
Thanks - but no good

My bad... I forgot to mention I am on Linux... MFC will not do... But the question deals with STL - isn't there an STL way to do what I asked?​
 

mikledet

New member
Thanks

This looks like a very nice article indeed. I just thought that the code posted thre was MFC from the headlines ect... Hmmm I guess that the answer to my question then is - "there is no "builtin" way to do what you want"... eh? I will have to consider now what is better - to add this class to my code - or just use the pointers... Thanks again.​
 
למעלה