PDA

View Full Version : Proper syntax for declaring a vector of vectors using STL


javaman99
05-06-2002, 10:09 PM
vector<vector<Edge> > temp1(size);


this makes a vector which contains size vectors. The problem is the internal vectors are all of the defualt stl size. How would I properly make it so that the internal vectors are the same size as the one holding them, essentially creating a square matrix.

sans-hubris
05-07-2002, 02:32 AM
The easiest way would be to create another class that contains your type of vector<Edge> and make a vector of that.

kmj
05-07-2002, 10:19 AM
or you could push_back() size items into each of the inner vectors...

sans-hubris
05-09-2002, 03:21 AM
Argh! Sorry, there is an easier way than what I said.

int i;
vector< vector<Edge> > temp1(size);
for(i=0; i<FOOBAR; i++) {
vector<Edge> inner_tmp(inner_size);
//Do stuff to inner_tmp here...
temp1.push_back(inner_tmp);
}

That's going to be the easiest way to set the sizes of the inner vectors.

javaman99
05-11-2002, 06:26 PM
Actually the easiest way is

vector <vector<Edge> > temp1(size, size);

I had to ask around to get that one though but it works