Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr and polymorphism
From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2010-02-23 09:53:15


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 23 February 2010, Abderrahmane Madani wrote:
> void foo(shared_ptr<D1>) {}
> void foo(shared_ptr<D2>) {}
>
> int main()
> {
> shared_ptr<E> e(new E);
> foo(e);
> return 0;
> }
> the compiler say that the foo(boost::shared_ptr<E>&)' is ambiguous.
>
> Please, can someone help me to understand why and how can I fix this
> problem without changing the functions name. Thanks
>
> Boost 1.35
> GCC 4.4.1

Your code should work with boost 1.36 or later. Or, does something like the
following help?

void foo_impl(shared_ptr<D1>, D1 *) {}
void foo_impl(shared_ptr<D2>, D2 *) {}

template<typename T>
void foo(shared_ptr<T> sp)
{
        foo_impl(sp, sp.get());
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkuD69wACgkQ5vihyNWuA4X31QCgoVlzHMDCUArjsUNWmlydSfvr
XNUAoIJJMA+RuBG4A3meuhJDMBOiQ+qK
=rGPY
-----END PGP SIGNATURE-----


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