复合模板
Compound template
本文关键字:复合 更新时间:2023-10-16
我正在尝试制作"复合"模板类型。像这样的东西
template <typename A, typename T>
class configurator
{
public:
configurator(const A<T> & adapter) : m_adapter(adapter) {}
private:
A<T> m_adapter;
};
编译器抱怨
error: expected ')'
configurator(const A<T> & adapter
^
为什么这不起作用?有可能让它工作吗?
A
被声明为类型模板参数;不能将其用作模板名称并为其指定模板参数。
您需要模板模板参数,例如
template <template <typename> typename A, typename T>
class configurator
顺便说一句,如果A
应该使用多个模板参数,您可以使用模板参数包指定A
:
template <template <typename...> typename A, typename T>
class configurator
相关文章:
- 算术复合运算符重载为非成员
- C++模板函数中的初始化 - 新的初始值设定项表达式列表被视为复合表达式
- 时间复杂度 当具有复合数据类型(如元组或对)时?
- HDF5Cpp 扩展复合数据集超板问题
- 返回复合模式的复合对象不返回整个对象
- 如何处理模板类中的复合类型
- 重载 C++ 中的复合运算符 (.*)
- C++析构函数调用两次,堆栈分配的复合对象
- H5Tget_member_type() 返回复合 HDF5 数据类型的奇怪值
- 复合类型的动态数组
- 为什么这个复合语句作为用大括号和括号括起来的语句序列似乎不是有效的语句表达式
- 对复合分配中的"常量"的混淆
- C 复合赋值运算符 ^= 平均值
- 复合赋值运算符C++概念
- 有没有办法改变概念中的复合需求返回的类型?
- 在未初始化的变量上使用复合赋值运算符(+=, ..)不是C++中的UB?
- 复合赋值运算符是否不如 C++ 精确?
- 使用static_cast而不是复合运算符
- 重载C++中的复合赋值运算符
- 用推广make_shared和make_unique的方法复合指针特征类