Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-09-30 21:33:29


"Philippe A. Bouchard" <philippe_at_[hidden]> writes:

> David Abrahams wrote:
>
> [...]
>
>>> Correction:
>>> template <typename U>
>>> shifted_ptr(shifted_ptr::details::stype<U> *);
>>>
>>
>> This still exposes an unmanaged raw pointer, doesn't it?
>
> No, not this one because because the address will point to the beginning of
> the allocated block before the constructor is called. So it would be
> possible to delete the block with any other pointer:
>
> stype<int> * p = new stype<int>(9);
>
> delete p; // This delete will work

So, despite that you said "no", the answer is "yes, it still exposes
an unmanaged raw pointer" AFAICT.

There are other reasons not to do that, for example exception safety.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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