J
jknupp
In the following program, if the call to bar does not specify the type
as <int>, gcc gives the error "no matching function for call to
‘bar(A&, <unresolved overloaded function type>)’". Since bar
explicitly takes a pointer-to-member with no parameters, why is the
lookup for the overloaded function not able to use the number of
arguments to determine the appropriate function? Is there a relevant
portion of the standard that governs the lookup rules in this case?
Thanks in advance,
Jeff
#include <iostream>
using namespace std;
class A
{
public:
int foo()
{
cout << "int foo" << endl;
return 5;
}
template <class A>
void foo (A a)
{
cout << "template foo" << endl;
}
};
template <class Type, class Obj>
void bar (Obj& obj, Type (Obj::*func)())
{
Type t = (obj.*func)();
cout << "TYPE: " << t << endl;
}
int main ()
{
A a;
bar<int>(a, &A::foo); //<int> required, even though only one of the
functions takes no arguments
bar(a, &A::foo); //doesn't compile
}
as <int>, gcc gives the error "no matching function for call to
‘bar(A&, <unresolved overloaded function type>)’". Since bar
explicitly takes a pointer-to-member with no parameters, why is the
lookup for the overloaded function not able to use the number of
arguments to determine the appropriate function? Is there a relevant
portion of the standard that governs the lookup rules in this case?
Thanks in advance,
Jeff
#include <iostream>
using namespace std;
class A
{
public:
int foo()
{
cout << "int foo" << endl;
return 5;
}
template <class A>
void foo (A a)
{
cout << "template foo" << endl;
}
};
template <class Type, class Obj>
void bar (Obj& obj, Type (Obj::*func)())
{
Type t = (obj.*func)();
cout << "TYPE: " << t << endl;
}
int main ()
{
A a;
bar<int>(a, &A::foo); //<int> required, even though only one of the
functions takes no arguments
bar(a, &A::foo); //doesn't compile
}