如何将std :: vector设置为模板的默认参数
How to set std::vector as default parameter of template?
我想做一个具有两个模板参数的模板类。首先 - n 是一类变量默认设置为int
和第二容器是stl
的容器,默认值设置为std::vector
。
#include <iostream>
#include <vector>
template <class N=int,
template <class T=N, class Allocator=std::allocator<N>>
class container=std::vector>
class foo{
container<N> cont;
};
int main()
{
foo f;
}
当我创建上面类的对象f
没有模板参数时,编译器写了一个foring错误:
In function 'int main()':
15:9: error: missing template arguments before 'f'
我希望foo
等于foo<int, std::vector>
声明。
我的班级定义在哪里?
使用C 14或之前,您需要编写foo<>
才能实例化模板。
从c 17上开始,它实际上只是因为class模板参数扣除而撰写时,它的作用。如果您的编译器支持它,则可以考虑使用-std=c++17
更新C 语言版本。
相关文章:
- 使函数参数默认为周围范围
- 如何将值传递给其参数(默认参数)
- 当“std::make_index_sequence”和“std::index_sequence”用于模板参数默认类型时
- C ,构造器中允许的参考参数默认值
- 哪些规则控制参数默认赋值?
- 错误:上一个规范后给出的参数默认参数
- 是否可以设计一个包含模板参数默认值的类
- 构造函数中参数C++默认值
- 如何设置依赖于其他参数的参数默认值
- C++模板参数默认函数实现
- QInput对话框参数默认值
- g++4.8.2上列表方法参数默认初始化时出错
- 在函数定义中指定参数默认值会导致错误 C2143:语法错误:'='之前缺少')'
- 函数模板:将第一个模板参数默认为第二个
- 模板模板参数默认可以引用其他模板类型的参数
- 参数默认为先例参数的值
- 如何修改一个类,使它只有一个成员函数,所有参数默认
- 内置类型的模板参数默认值
- 是否可以使用构造函数或对象作为其他类方法的参数默认值?
- 模板参数默认为更高版本