Vector version of pointer pointer array

Aug 29, 2021 at 12:59pm

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;
Aug 29, 2021 at 1:30pm
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 Aug 29, 2021 at 1:31pm
Sep 4, 2021 at 8:31am
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 Sep 4, 2021 at 8:39am
Sep 4, 2021 at 5:42pm
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.