Convert iterator to pointer?

前端 未结 12 2285
野性不改
野性不改 2020-12-14 14:20

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

12条回答
  •  借酒劲吻你
    2020-12-14 14:48

    If you can, a better choice may be to change the function to take either an iterator to an element or a brand new vector (if it does not modify).

    While you can do this sort of things with arrays since you know how they are stored, it's probably a bad idea to do the same with vectors. &foo[1] does not have the type vector*.

    Also, while the STL implementation is available online, it's usually risky to try and rely on the internal structure of an abstraction.

提交回复
热议问题