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.

Reply via email to