mchen
mchen

Reputation: 10166

What's the legal syntax to define nested template?

I have the following nested template

class A {
    template <typename T> class B {
        template <typename U> void foo(U arg);
    };
};

I am trying to define the nested template like so:

template <typename T, typename U> void
A::B<T>::foo(U arg) {...}

But am getting declaration is incompatible with function template error. What's the legal syntax to do so?

Upvotes: 8

Views: 1159

Answers (1)

Konrad Rudolph
Konrad Rudolph

Reputation: 546143

You need to separate the template declarations:

template <typename T>
template <typename U>
void
A::B<T>::foo(U arg) { … }

Upvotes: 14

Related Questions