Boost logo

Boost :

From: Jonathan Biggar (jon_at_[hidden])
Date: 2007-11-20 11:35:05


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. The keywords have incompatible meanings to me
> and therefore I fail to make sense of it. If you template the argument, then
> you're saying you'll accept any type of pointer as long as it will still
> compile, and the explicit implies no explicit conversions to Y, which
> shouldn't happen anyway due to the template indicating any argument is valid
> as long as it complies.

You're incorrect on the second restriction. It doesn't mean "no explicit
conversions to Y", it means "no implicit conversions from Y to shared_ptr<T>".

So as long as you use explicit construction, like this:

        shared_ptr<A> myPtr(x);

you can use any 'x' that is implicitly convertible to an 'A *'.

-- 
Jon Biggar
Levanta
jon_at_[hidden]
650-403-7252

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