1

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`

}

0

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.