Boost logo

Boost :

Subject: Re: [boost] casting a shared_ptr from void with custom deleter
From: Peter Dimov (pdimov_at_[hidden])
Date: 2009-03-20 10:03:41


Kenny Riddile:
> I'm trying to do something like this:
>
> boost::shared_ptr<const Foo> fooPtr( boost::static_pointer_cast<const
> Foo>(typeErasedFoo), CustomDeleter<const Foo>() );
>
> where typeErasedFoo is of type:
>
> boost::shared_ptr<const void>

What does CustomDeleter do?

There is no constructor that takes another shared_ptr and a deleter. You can
either associate a raw pointer with a deleter:

    shared_ptr( Y* p, D d );

or you can make a copy of another shared_ptr:

    shared_ptr( shared_ptr<Y> const& r );

Since the two shared_ptr instances now refer to the same object, it is not
possible for one of them to use deleter A and for the other to use a deleter
B. There only exists a single deleter, which is shared between the two.

Depending on what you're trying to do,

http://www.boost.org/doc/libs/1_38_0/libs/smart_ptr/sp_techniques.html#another_sp

may give you some ideas though.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk