Boost logo

Boost :

Subject: Re: [boost] [shared_ptr] towards a static_cast applied to smart_ptr
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-10-03 02:21:56

----- Original Message -----
From: "Emil Dotchevski" <emil_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, October 03, 2008 8:07 AM
Subject: Re: [boost] [shared_ptr] towards a static_cast applied to smart_ptr

> On Thu, Oct 2, 2008 at 10:41 PM, vicente.botet <vicente.botet_at_[hidden]>
> wrote:
>> This is normal as void* is not convertibel to X*. But in my program I can
>> ensure that the pointeed object by ptr_void is a X pointer. So it would
>> be
>> safe to do a kind of static_cast on shared_ptr. At the end smart pointers
>> should behave like pointers.
>> Can I achieve this already? I was thinking is something like something
>> like
>> shared_ptr<X> ptrX2(boost::static_cast<shared_ptr<X> >(ptr_void));
> Use boost::static_pointer_cast. You can also use the aliasing
> constructor to do tricks like make a shared_ptr point to a subobject
> of the pointee, for example you can make a shared_ptr<float> from a
> shared_ptr<std::pair<int,float> >.

Thanks Emil for pointing me to static_pointer_cast.

I understand now the use of aliasing.

Thanks again,

Boost list run by bdawes at, gregod at, cpdaniel at, john at