vector of pointer to object - how to avoid memory leak?

后端 未结 3 598
耶瑟儿~
耶瑟儿~ 2020-12-20 09:40

How do we ususaly deal with a vector whose elements are pointers to object? My specific question is the comment at the end of the code supplied below. Thanks.



        
3条回答
  •  悲哀的现实
    2020-12-20 09:55

    Use an array of shared_ptr, or similar smart pointer. And note that your base class must have a virtual destructor for this code to work correctly.

提交回复
热议问题