On Jan 21, 2014, at 7:21 PM, Martin Owens wrote:
Thanks for the push Krzysztof,
I got ptr_list working I think the way you wanted, have a look at r12969
and see if it's the way you imagined.
BTW, in general a safer approach could be to use boost::shared_ptr<> /
Of course, as with any "smart" pointer we developers have to remember that they
are easy to misuse and could get out of hand or easily not do what you expect. In this
specific case, we probably just need to avoid setting up cyclic loops (i.e.
Using this type we'd get for a member declaration:
std::vector<boost::shared_ptr<MyType> > _children;
And to add one,
_children.push_back(boost::make_shared<MyType>(/* params for MyType's
These also have gotten into c++11, so if we want to later on we can add a little autoconf
magic to have the proper one brought in at build time.
One of the biggest advantages of shared_ptr<> is that you won't get dangling
pointers passed around that point to objects that have already been deleted.
Boost::ptr_list does not provide this same safety.