Can I call `delete` on a vector of pointers in C++ via for_each ?

后端 未结 7 1538
醉梦人生
醉梦人生 2021-01-14 08:32

Suppose I have a std::vector objs (for performance reasons I have pointers not actual Objs).

I populate it with obj.push

7条回答
  •  -上瘾入骨i
    2021-01-14 09:30

    Instead of trying to solve the deletion problem, you can make it go away completely by storing shared_ptrs in the vector, or by using boost's ptr_vector (see http://www.boost.org/doc/libs/1_39_0/libs/ptr_container/doc/tutorial.html).

提交回复
热议问题