Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-05-14 15:32:10


Jean-François Brouillet wrote:

> As far as I understand what is going on, the reason why
> the runtime is reporting a "double free" is because two independently
> constructed shared_ptrs' do not share the same reference count,
> which intrusive_ptr would allow me to do, except that intrusive_ptr
> doesn't vary "polymorphically" with its body as shared_ptr does.

I'm not sure what you mean by that.

intrusive_ptr<> aside, you need to derive from enable_shared_from_this<> if
you want to create a shared_ptr<> to this as explained in:

http://boost.org/libs/smart_ptr/enable_shared_from_this.html

but you can't do this in a constructor, because the outer shared_ptr<>
hasn't been created yet. Use a static create() function as explained here:

http://boost.org/libs/smart_ptr/sp_techniques.html#in_constructor

The other option is intrusive_ptr<>.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net