Boost logo

Boost :

From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2007-11-20 12:30:52

Sid Sacek wrote:
> template<class T> class shared_ptr
> {
> template<class Y>
> explicit shared_ptr( Y * p ): px( p ), pn( p ) // Y must be complete
> {
> detail::sp_enable_shared_from_this( pn, p, p );
> }
> };
> I've tried really hard to figure out what it means when a constructor is both a template as well as explicit.

shared_ptr's constructor is explicit because its interface is not very
safe. It takes ownership of the passed pointer, so that's why you must
be sure that's really what you want to do.
Other smart pointers have similar behaviours.

There would be no need for it to be explicit if shared_ptr took in-place
factories instead, or even objects it would copy or move, like any
normal container.

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