Topic: Q: templates and overloading ambiguites


Author: f_clerc@effix.fr (Fabrice Clerc)
Date: 1996/05/02
Raw View

I'm wondering...
What are the rules compilers are supposed to follow to determine which
function to call in the presence of overloaded template functions?

If I have

[1] void f(A&)
[2] void f(A const&)

A a; f(a); compiles ok

but if f is a template function
[1] template <class T> void f(T&)
[2] template <classT> void f(T const&)

A a; f(a); gives an "overloading ambiguity" error with some of the
compilers I have access to.  Is not [1] supposed to be called?  How is the
compiler supposed to proceed (does it have to instantiate the template
functions to be able to select one?)?

Now, suppose I have
[1] template <class T> void f(T&,void (T::*)())
[2] template <class T> void f(T const&,void (T::*)() const)

Are these two functions sufficient to deal unambigously and "naturally"
with the following cases?  If not, how to achieve this?

struct A {
  void foo() {}
  void bar() const {}
};

A a;
f(a,&A::foo)  -> calls [1] ?
f(a,&A::bar) -> calls [2] ? (or compile error?)

A const ca;
f(ca,&A::foo) -> compile error ?
f(ca,&A::bar) -> calls [2] ?

Thanks

---------
Fabrice Clerc  -  f_clerc@effix.fr
Effix SA       -  6, rue Godefroy, 92821 Puteaux, France
                  V: +(33) 1 47 62 64 66
                  F: +(33) 1 47 62 64 99



[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]