我有以下嵌套模板
class A {
template <typename T> class B {
template <typename U> void foo(U arg);
};
};
Run Code Online (Sandbox Code Playgroud)
我试图像这样定义嵌套模板:
template <typename T, typename U> void
A::B<T>::foo(U arg) {...}
Run Code Online (Sandbox Code Playgroud)
但我得到declaration is incompatible with function template错误.这样做的法律语法是什么?
Kon*_*lph 12
您需要分离模板声明:
template <typename T>
template <typename U>
void
A::B<T>::foo(U arg) { … }
Run Code Online (Sandbox Code Playgroud)