Templated function in templated class

Viewed 250

With

template <typename T>
class Foo {
public:
    template <int x>
    void bar () {}
};

the following compiles:

void fooBar ()
{
    Foo<int> f;
    f.bar<1>();
}

but the following does not (with "error: expected primary-expression before ')' token" in gcc 5.4.0 with -std=c++14).

template <typename T>
void fooBar ()
{
    Foo<T> f;
    f.bar<1>();
}

If I try to explicitly call the second version, with e.g.

fooBar<int>();

then gcc additionally complains about

"invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator<'".

Is there any reason why the second version is invalid? Why is gcc treating the '<' as an operator rather than the beginning of a template parameter list?

1 Answers
Related