Re: ambiguous method calling
In article <20071218141105.C32366@buique.cin.ufpe.br>, Thiago Souto
Maior Cordeiro de Farias <tsmcf@cin.ufpe.br> wrote:
Hi,
I have troubles using templates with multiple inheritance, what
generated an
error (in both Visual Studio 2005 and g++ 3.3.0) refering to an
ambiguous
call. Ambiguous? the type is given in the calling function, but the
compiler
needs the scope for the correct base where the desired method relies.
There is any workaround to fix this problem?
the problem is f(float), f(int),f(char) are all visible in class D and
they are non templated functions so the ambiquity.
simplest solution is to write a metafunction to determine the proper
base class so the template selects the correct one
template<class T> struct BaseClass;
template<> struct BaseClass<float> {typedef A type;};
template <> struct BaseClass<int> {typedef B type;};
template <> struct BaseClass<char> {typedef C type;};
class D : public A, public B, public C {
public:
template <typename T> void a(T t) {
f(t) ; // change to
Base?lass<T>::type::f(t);
}
};
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]