2
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 correct to me, but compiler gives this ugly error which I am unable to understand:

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

For your convinence, code is posted here -> http://www.ideone.com/vtP7G

Nawaz
  • 353,942
  • 115
  • 666
  • 851

1 Answers1

3
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]...

Which is an error.

Thomas Edleson
  • 2,175
  • 1
  • 16
  • 19