szh
szh

Reputation: 41

compile error when a template function call a template static function in a template class

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

Answers (1)

rafix07
rafix07

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

Related Questions