Possible Duplicate:
Templates: template function not playing well with class’s template member function
template <typename T>
struct A
{
template <int I>
void f();
};
template <typename T>
void F(A<T> &a)
{
a.f<0>(); // expected primary-expression before ‘)’ token
}
int main()
{
A<int> a;
a.f<0>(); // This one is ok.
}
What it’s all about?
When a dependent name is used to refer to a nested template, the nested name has to be prepended with the keyword
templateto help the compiler understand that you are referring to a nested template and parse the code correctlyInside
mainthe nameais not dependent, which is why you don’t need the extratemplatekeyword. InsideFnameais dependent, which is why the keyword is needed.This is similar to the extra
typenamekeyword when referring to nested type names through a dependent name. Just the syntax is slightly different.