how would i make a pointer to a vector?
thx
This is a discussion on pointers to vectors within the C++ Programming forums, part of the General Programming Boards category; how would i make a pointer to a vector? thx...
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 used to be an adventurer like you... then I took an arrow to the knee.
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.