Boost logo

Boost :

From: Philippe A. Bouchard (philippe_at_[hidden])
Date: 2003-09-30 17:45:12


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

** Correction again: **

template <typename T>
    class stype
    {
        friend class shifted_ptr<T>;

        shifted_header h;
        T s;

    public:
            stype() : i() {}

        template <typename T>
            stype(T const & t) : i(t) {}

        template <typename T, typename U>
            stype(T const & t, U const & u) : i(t, u) {}
    };

Philippe


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