This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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)

int main()
//  proper way (according to g++) to call non-templated print
//  call(static_cast<void(*)()>(&print));

    return 0;

The correct output should be:
7 6

Thanks for your help, Rodolfo Lima.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]