how would i make a pointer to a vector?
thx
Printable View
how would i make a pointer to a vector?
thx
Post an example of a vector container.
Kuphryn
There aren't very many good reasons to do that. Why do you want to?
The answer is the same as for any other type.
Maybe...
Code:vector<int> int_vect;
vector<int> * ptr_int_vect;
ptr_int_vect = &int_vect;
i wanted to do it so that a class can access a vector located in the main program, without having to pass it as a parameter for every function call.
That might be one of the few reasons to have a pointer, although if the vector will always be there (and can never be null), then a reference would probably be better.
I think it would be tons better to use a global static class or namespace. With a pointer, you'd have to handle allocation, scope, errors and such.