Avoiding iterator invalidation using indices, maintaining clean interface

前端 未结 4 702
悲&欢浪女
悲&欢浪女 2021-02-02 02:24

I have created a MemoryManager class which is basically a wrapper around two vectors of pointers that manage lifetime of heap-allocated objects.

O

4条回答
  •  花落未央
    2021-02-02 03:08

    You can implement your own iterator class which handles things the way you prefer. Then your begin() and end() can return instances of that class. For example, your custom iterator could store an integer index and a pointer to the vector itself, thereby making the iterator remain valid even in the face of reallocation.

提交回复
热议问题