c++ deleting vector class member memory in destructor

前端 未结 4 2055
天涯浪人
天涯浪人 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:24

    The vector is cleaned up for you already! When a class gets destructed all of it's members destructors are also called. In this case v's destructor is called, which cleans up whatever it allocated.

    Non-static members' dtors are called when you reach the closing } of the destructor in the reverse order they were declared in. Then your base class destructor is called, if present.

提交回复
热议问题