Vector version of pointer pointer array


Are these roughly equivalent? Not sure if the *'s are in the right place for the vector

1
2
3
4
5

int **myArr;

std::vector<int*> *myVec;
no.
int **myarr //two dimensions of pointers

is similar to
vector<vector <int> > mv; //two dimensions of vectors

or, if you must use pointers (I would try to avoid)

vector <int*> myvec; //one dimension of vector, one dimension of pointers.

you have 3 dimensions, with the vector in the middle. this would be aggravating to use.
Last edited on
Something that vector has that new/delete doesn't do by itself is on the fly allocation when adding a new element. That you would have to write yourself. Basically you need to create a memory management system for when an array overflow is eminent, whereas vector has that baked in.

I totally agree with Jonnin that a vector of vectors is extremely recommended instead, but creating your own memory manager can be interesting practice.
Last edited on
I generally prefer to keep everything 1d as much as possible for a variety of reasons. But everyone's needs are different.
Topic archived. No new replies allowed.