c++ deleting vector class member memory in destructor

前端 未结 4 2104
天涯浪人
天涯浪人 2021-01-19 16:42

I have a class containing a vector member variable. I know that vectors stored on the stack will be cleaned up (i.e. memory free\'d) when they go out of scope, but I\'m not

4条回答
  •  渐次进展
    2021-01-19 17:22

    There is always ONLY ONE way to destroy an object, and that is by its destructor (in contrast, you can construct objects in several ways). STL containers were designed specifically to avoid such micromanagement of memory within data structures. If you are having to explicitly allocate or free memory in an STL container, you're doing it wrong.

提交回复
热议问题