I have a std::vector
with n
elements. Now I need to pass a pointer to a vector that has the last n-1
elements to a function.
F
For example, my
vector
contains (5,2,6,87,251). A function takesfoo vector
and I want to pass it a pointer to (2,6,87,251).*
A pointer to a vector
is not at all the same thing as a pointer to the elements of the vector.
In order to do this you will need to create a new vector
with just the elements you want in it to pass a pointer to. Something like:
vector tempVector( foo.begin()+1, foo.end());
// now you can pass &tempVector to your function
However, if your function takes a pointer to an array of int, then you can pass &foo[1]
.