Boost logo

Boost :

From: Pierre THIERRY (nowhere.man_at_[hidden])
Date: 2006-06-12 19:53:19


Le Tue, 31 Jan 2006 11:06:51 -0500, me22 a écrit :
> On 31/01/06, Pierre THIERRY <nowhere.man_at_[hidden]> wrote:
>> + shared_ptr & operator=(T * r)
>> + {
>> + this_type(r).swap(*this);
>> + return *this;
>> + }
>> +
>
> That results in implicitly creating a shared_ptr from a raw pointer,
> which as I understand it is explicitly disallowed because it means
> that simple code such as the following will fail:
> int *p = new int;
> shared_ptr<int> sp;
> sp = p;
> sp = p;

I understand, but the following code would fail the same way without
compilation warnings:

int p* = new int;
shared_ptr<int> sp;
sp.reset(p);
sp.reset(p);

> My understanding is that the operator=(T*) is purposefully not there
> to make this more explicit.

But this also renders some uses impossible, like this one:

stack<foo*> fooS;
while(shared_ptr<foo> = fooS.pop())
{
        ...
}

Sorry for answering so late to this (now) old thread. If I should start
it again for clarity, just tell me.

Lately,
Nowhere man

-- 
nowhere.man_at_[hidden]
OpenPGP 0xD9D50D8A

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