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
If your function really takes vector
(a pointer to vector), then you should pass &foo
since that will be a pointer to the vector. Obviously that will not simply solve your problem, but you cannot directly convert an iterator to a vector, since the memory at the address of the iterator will not directly address a valid vector.
You can construct a new vector by calling the vector constructor:
template vector(InputIterator, InputIterator)
This constructs a new vector by copying the elements between the two iterators. You would use it roughly like this:
bar(std::vector(foo.begin()+1, foo.end());