|
Boost : |
From: me22 (me22.ca_at_[hidden])
Date: 2006-01-31 11:06:51
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;
Since it would be the same as:
int *p = new int;
shared_ptr<int> sp;
sp.reset(p);
sp.reset(); // which has the same effect as delete p, in this case
sp.reset(p); // sp is now holding a pointer to unallocated memory
My understanding is that the operator=(T*) is purposefully not there
to make this more explicit. It should help in migrating to shared_ptr
as well, since if sp was previously an int* that was manually deleted
at the end of the scope, the code would have been fine.
- Scott McMurray
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk