Topic: cv overloading and template argument deduction
Author: the_wid@my-deja.com (Tom)
Date: Mon, 11 Sep 2000 23:09:30 GMT Raw View
Check out this small example:
#include <functional>
#include <iostream>
struct A
{
int f() const {std::cout << "const f\n";}
int f() {std::cout << "non-const f\n";}
};
int main()
{
A a;
std::mem_fun(&A::f) (&a);
std::cin.get();
}
It compiles without warning on gcc 2.95 with stlport, and produces the
output:
const f
mem_fun is a template function with two overloads - one for constant
member functions. The constant overload is chosen by gcc, and I have
no idea why.
Is this correct? I would have thought that the call to mem_fun would
be ambiguous since the one returning a const_mem_fun_t and the one
returning a mem_fun_t seem to both be possibles, and overload
resolution should be unable to choose between them, shouldn't it?
Certainly if you replace "int f() const" with "int f(int i)" then gcc
gives the error I would expect.
I delved into the CD2 standard without success. 14.8.2, 13.3 and 13.4
all seem relevent, but I was unable to put it all together.
Thanks,
Tom
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]