Error compiler template errors

template<typename T> struct function { typedef T type; template<typename U> static void f() {} }; template<typename T> struct caller { int count; caller(): count() {} void operator()() { count++; T::f<typename T::type>(); } }; int main() { caller<function<int> > call; call(); return 0; } 

This seems right to me, but the compiler gives this ugly error, which I cannot understand:

prog.cpp: In the member function 'void caller :: operator () ():
prog.cpp: 17: error: expected `('before'> token
prog.cpp: 17: error: expected primary expression before ') token

For your convenience, the code is posted here β†’ http://www.ideone.com/vtP7G

+2
c ++ templates
source share
1 answer
 T::template f<typename T::type>(); 

Without this β€œtemplate”, the code is parsed as:

 T::f [less-than operator] typename T::type [greater-than operator]... 

What mistake.

+3
source share

All Articles