
Just a little problem that I can't fix. Suppose that I have these four classes class B {}; class D1: public B {}; class D2: public B {}; class E: public D1 {}; this test: void foo(D1 *) {} void foo(D2 *) {} int main() { E *e = new E; foo(e); return 0; } work just fine but this one 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 regards

-----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-----
participants (2)
-
Abderrahmane Madani
-
Frank Mori Hess