|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-05-10 05:39:50
From: "artc_prismcs" <artc_at_[hidden]>
>
> The marked call in the code below requires implicit conversion
> between compatible shared pointer types.
>
> At least two compilers (MSVC6 and Sun Workshop6) consider the marked
> call ambiguous.
>
> Remove the second overloaded() function, and the marked call is
> compiled without error.
>
> Replace all the shared pointers by raw, and all three calls to the
> overloaded methods would be resolved correctly.
>
> Is this a shortcoming of the compilers, boost::shared_ptr or the
> language?
boost::shared_ptr and the language are at fault. The templated copy
constructor is always considered by the overload resolution; its definition
might not compile, but its declaration is fine. There are some tricks one
can play with the language, but so far, I haven't been able to find a
solution.
> #include <boost/shared_ptr.hpp>
>
> class MyType { };
> class DerivedType : public MyType { };
> class OtherType {};
>
> void overloaded( const boost::shared_ptr<MyType> & p ) {}
> void overloaded( const boost::shared_ptr<OtherType> & p ) {}
In this particular situation, you can turn the first overload into a
template so that OtherType would go to the non-template version and the rest
of the types would go to the template.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net