Hi,
Trying to compile the attached code with GCC 5.3.0 gives the error:
templ_bug.cpp: In function ‘void g()’:
templ_bug.cpp:15:12: error: expected primary-expression before ‘)’ token
T().f<t>();
^
templ_bug.cpp: In instantiation of ‘void g() [with T = A; int t = 0]’:
templ_bug.cpp:19:10: required from here
templ_bug.cpp:15:8: error: invalid operands of types ‘<unresolved
overloaded function type>’ and ‘int’ to binary ‘operator<’
T().f<t>();
^
However, if I uncomment the commented line, it works fine. I cannot
understand why this should make a difference. Is there a mistake in the
code or a bug in GCC?
Best regards,
Marcel
#include <iostream>
using namespace std;
class A
{
public:
template <int t> void f() { cout << "Hello world" << endl; }
};
//template <class T> void f();
template <class T, int t>
void g()
{
T().f<t>();
}
int main() {
g<A,0>();
}