Hello
Suppose I have:
I wonder if that will clean m_vector after smart pointer is deleted?Code:class object { public: boost::ptr_vector<some_object> m_vector; }; boost::shared_ptr<object> o(new object()); o->m_vector.pushback(new some_object());
This is a discussion on ptr_container within the C++ Programming forums, part of the General Programming Boards category; Hello Suppose I have: Code: class object { public: boost::ptr_vector<some_object> m_vector; }; boost::shared_ptr<object> o(new object()); o->m_vector.pushback(new some_object()); I wonder if ...
Hello
Suppose I have:
I wonder if that will clean m_vector after smart pointer is deleted?Code:class object { public: boost::ptr_vector<some_object> m_vector; }; boost::shared_ptr<object> o(new object()); o->m_vector.pushback(new some_object());
Once the o container goes out of scope, delete should be called on any object items stored. This will call the destructor for all these object items. Internally, the destructor for the object class will then call the destructor for any data members which means the m_vector member should be destructed and any some_object's contained within should be properly dealt with.
I used to be an adventurer like you... then I took an arrow to the knee.
I was confused by hk_mp5kpdw's response when I first read it, but now I see (and agree with) what was said.
You do not need to do any extra work, everything will be cleaned up automatically.
Thanks.