I have a problem when creating a function pointer of an overloaded function leads to a compilation error in g ++ 4.7 and g ++ 4.8, but not in g ++ 4.4, g ++ 4.6 or clang ++ 3.2 (and possibly VS2010).
Having a little understanding, find out if there is a problem with g ++ or with my code, I still can not solve. Are overload resolution rules applicable to converting function pointers other than those that apply to function calls?
This is some minimized code that demonstrates the problem:
template < class T > struct Dummy { typedef T value_type; value_type value; }; template < class T > typename T::value_type f (const T& x) { return x.value; } template < class T > T f (Dummy< T > const& x) { return x.value + 1; } int main (int, char**) { Dummy< int > d = { 1 };
clang ++ 3.2, g ++ 4.4 and g ++ 4.6 compile this with -Wall -pedantic --std=c++98 without warning.
g ++ 4.7 and g ++ 4.8, however, give the following error message:
test.cc: In function 'int main(int, char**)': test.cc:15:45: error: converting overloaded function 'f' to type 'int (* const)(const struct Dummy<int>&)' is ambiguous test.cc:6:18: error: candidates are: typename T::Type f(const T&) [with T = Dummy<int>; typename T::Type = int] test.cc:9:3: error: T f(const Dummy<T>&) [with T = int]
Is this a problem with newer versions of g ++, or is my code really wrong?
If so, how can this ambiguity be resolved?
source share