Cleaning up an STL list/vector of pointers

后端 未结 15 1361
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 21:41

What is the shortest chunk of C++ you can come up with to safely clean up a std::vector or std::list of pointers? (assuming you have to call delet

15条回答
  •  情深已故
    2020-11-28 22:39

    It's really dangerous to rely on code outside of the container to delete your pointers. What happens when the container is destroyed due to a thrown exception, for example?

    I know you said you don't like boost, but please consider the boost pointer containers.

提交回复
热议问题