Pointers to elements of std::vector and std::list

后端 未结 7 887
借酒劲吻你
借酒劲吻你 2020-12-05 06:56

I\'m having a std::vector with elements of some class ClassA. Additionally I want to create an index using a std::map

相关标签:
7条回答
  • 2020-12-05 07:39

    Use std::deque! Pointers to the elements are stable when only push_back() is used.

    Note: Iterators to elements may be invalidated! Pointers to elements won't.

    Edit: this answer explains the details why: C++ deque's iterator invalidated after push_front()

    0 讨论(0)
提交回复
热议问题