Reputation: 41
A compile error when I write template in c++, hard to understand for me. This is the code
template<typename T>
struct S
{
template<typename U>
static void fun()
{
}
};
template<typename T>
void f()
{
S<T>::fun<int>(); //compile error, excepted primary expression before `int`
}
Upvotes: 1
Views: 26
Reputation: 20938
You need to put template
S<T>::template fun<int>();
^^^
to tell the compiler that <
between fun
and int
is the beginning of template arguments list. Otherwise, it will be interpreted as the <
(i.e., less-than) operator.
Upvotes: 2