Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-01-11 11:57:41


"Rani Sharoni" <rani_sharoni_at_[hidden]> writes:

> Consider the following:
> #include "boost/shared_ptr.hpp"
>
> struct B {};
> struct D : B {};
>
> void f(boost::shared_ptr<B>); // #1
> void f(boost::shared_ptr<int>); // #2
>
> int main()
> {
> boost::shared_ptr<D> dp(new D);
> f(dp); // #3 ambiguous call to overloaded function
> }
>
> #3 yield ambiguity since #1 and #2 have the same UDC rank using converting
> constructor regardless of further constraints (i.e. D* is convertible to
> B*).
> This problem is common to classes that has generalized copy/converting
> constructor and can be avoided using extra default parameter and SFINAE. I
> vaguely remember that I saw this technique in the new iterator adapter.

Yep, we discussed this on the committee reflector when the technique
was challenged in the iterators proposal. At the time Peter seemed to
think it was less important for shared_ptr than for iterators, though.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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