如何使用模板参数编写外部构造函数?

Chr*_*s_F 5 c++ templates constructor c++11

可以说我有以下结构.我该如何为此编写外联构造函数?

template <typename T>
struct foo
{
    template <typename Bar>
    foo(int n, Bar bar);
};
Run Code Online (Sandbox Code Playgroud)

0x4*_*2D2 7

您需要两个单独的模板声明:

template <typename T>
template <typename Bar>
foo<T>::foo(int n, Bar bar)
{
    // ...
}
Run Code Online (Sandbox Code Playgroud)