shared ptr - C++ destruction list -


i have class computation using callbacks. callbacks need allocate data (dynamic arrays) needs live outside of callback scope not after class destructs. thought make vector of auto_ptr destructed automatically when class destructs:

class myclass {     vector<auto_ptr<myobject>> thingstodie; }; 

the problem have lot of objects allocated , don't share base type can't use 1 vector this, , making vector every type lot of work.
hierarchy following:

auto_ptr_base (virtual destructor)       |  auto_ptr<t> 

will solve problem because like

class myclass {     vector<auto_ptr_base> thingstodie; }; 

and destruction virtually dispatched each specialized type automatically.
problem stl doesn't have hierarchy , don't want re-implement auto_ptr.
there other solution this?

you use vector<shared_ptr<void>>.

read this: why std::shared_ptr<void> work


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -