vector作为模板参数.所有的地狱都失去了
std::vector as template parameter... all hell breaks lose
我马上就要爆炸了…请有人指出目前这里有什么问题:
template <typename TType, template <typename ...> class Container, class Comparer>
Container<TType>* sort(const Container<TType>& container) {
...
}
当我尝试用std::vector作为容器形参来调用这个函数时,问题就出现了。我得到以下错误:
main.cpp:24:34: error: no matching function for call to 'func()'
main.cpp:24:34: note: candidate is:
main.cpp:14:6: note: template<class T, template<class ...> class Container> void func()
main.cpp:14:6: note: template argument deduction/substitution failed:
我是这样命名的:
std::vector<int>* m(sort<int, std::vector<int>, Comparer>(m));
当我从函数中删除模板模板参数时,它工作,但不与它一起…我使用的是MinGW附带的最新的c++编译器。IDE是NetBeans 7.3,不过这应该不会有太大影响。编译器参数为:
-std=c++11 -Wall -pedantic
谢谢每一个帮助,——乔伊
您应该提供一个模板,而不是从模板创建的特定类型。正确的调用应该是:
sort<int, std::vector, Comparer>(m)
注意,sort
本身提供了Container
的模板参数,就像const Container<TType>&
一样。显然将Container
设置为std::vector<int>
是没有意义的;你会要求编译器做std::vector<int><int>
相关文章:
- 主.cpp:18:20:错误:从"int*"转换为"int"会失去精度 [-fa
- 启动类函数作为失去引用的线程
- 为什么对引用的常量引用会失去其恒定性?
- 当指针在 cpp 17 中失去引用时,是否会调用非默认析构函数?
- 使shared_ptr失去对内存的所有权
- 从"SymbolInfo*"转换为"YYSTYPE {aka int}"会失去精
- C++:从 "const variable*" 转换为"uint32"会失去精度
- 数组在返回时失去价值(库存/菜单程序)C++
- 在DLL中,C 静态矢量会失去元素
- 为什么我的std :: Map失去了价值
- 当在QTableView上丢失焦点时,失去背景颜色
- strtoull() 的输出在转换为双精度然后又转换为 uint64_t 时会失去精度
- 特征在矩阵加法中失去负号
- 双缓冲的waveoutwrite()像地狱一样口吃
- 如何在不退出和失去断点的情况下重新加载重新编译的二进制文件
- C++:递归(变量失去值)
- C++错误:从“int*”转换为“int”会失去精度
- 从 double* 转换为 int 会失去精度
- QUdpSocket 失去有效性
- vector作为模板参数.所有的地狱都失去了