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
A vector is a container with full ownership of it's elements. One vector cannot hold a partial view of another, even a const-view. That's the root cause here.
If you need that, make your own container that has views with weak_ptr's to the data, or look at ranges. Pair of iterators (even pointers work well as iterators into a vector) or, even better, boost::iterator_range that work pretty seamlessly.
It depends on the templatability of your code. Use std::pair if you need to hide the code in a cpp.