This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Overload resolution compilation error
- From: Rodolfo Schulz de Lima <rodolfo at rodsoft dot org>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 19 Jul 2007 12:59:09 -0300
- Subject: Overload resolution compilation error
Hi, the code below doesn't compile with gcc-4.2, with the following error:
test.cpp: In function ‘int main()’:
test.cpp:19: error: no matching function for call to ‘call(<unresolved
overloaded function type>)’
It compiles and runs fine with Visual Studio 2005. I think the compiler
should see that if I'm calling the non-templated 'print' function and
there's no other non-templated 'print' overload, it should use
'void print()', with no ambiguity.
As I don't have a copy of the standard at hand, who's to blame not to be
standard compliant? g++ or Visual Studio?
#include <iostream>
using namespace std;
void print() { cout << "null" << endl; }
template<int i> void print() { cout << i << endl; }
template<int i, int j> void print() { cout << i << ' ' << j endl; }
template <class F> void call(F f)
{
f();
}
int main()
{
// proper way (according to g++) to call non-templated print
// call(static_cast<void(*)()>(&print));
call(&print);
call(&print<5>);
call(&print<7,6>);
return 0;
}
The correct output should be:
null
5
7 6
Thanks for your help,
Rodolfo Lima.