Boost logo

Boost :

From: Dave Abrahams (abrahams_at_[hidden])
Date: 2000-03-18 00:55:42


on 3/17/00 5:34 PM, Greg Colvin at gcolvin_at_[hidden] wrote:

> The impasse is that some users of smart pointers, myself
> included, actually want operator T*(). If you have generic
> code written to accept pointers then operator void*() won't
> do, and neither will get().
>

Ya know, I don't think I buy it. Could you give an example?

If you mean generic code as in "template code", it will just use the smart
pointer type instead, and no implicit conversion is needed (unless you
intend to do something evil which the interface of a raw pointer allows but
smart pointers do not, like pointer arithmetic).

Finally, I worry that allowing the implicit conversion will break this
smart_ptr<Derived> -> smart_ptr<Base> conversion or others like it:

void f(smart_ptr<Derived> d)
{
    smart_ptr<Base> b(d); // ambiguous?
}

at least that would be true for auto_ptr, since conversions proceed through
auto_ptr_ref.

-Dave


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