复合模板

Ros*_*rei 1 c++ templates template-templates

我正在尝试制作"复合"模板类型.像这样的东西

template <typename A, typename T>
class configurator
{
public:
    configurator(const A<T> & adapter) : m_adapter(adapter) {}
private:
    A<T> m_adapter;
};
Run Code Online (Sandbox Code Playgroud)

编译器抱怨

error: expected ')'
    configurator(const A<T> & adapter
                        ^
Run Code Online (Sandbox Code Playgroud)

为什么这不起作用?它可以使它工作吗?

son*_*yao 5

A声明为类型模板参数 ; 您不能将其用作模板名称并为其指定模板参数.

你想要模板模板参数.例如

template <template <typename> typename A, typename T>
class configurator
Run Code Online (Sandbox Code Playgroud)

BTW如果A应该使用您可以A使用模板参数包指定的多个模板参数:

template <template <typename...> typename A, typename T>
class configurator
Run Code Online (Sandbox Code Playgroud)