定义嵌套模板的法律语法是什么?

What's the legal syntax to define nested template?

本文关键字:语法 是什么 嵌套 定义      更新时间:2023-10-16

我有以下嵌套模板

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

我试图定义嵌套模板,像这样:

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

但是我得到declaration is incompatible with function template错误。这样做的法律语法是什么?

你需要把模板声明分开:

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