在函数中使用模板模板参数时没有匹配函数错误
no matching function error using template template parameters in a function
我正在尝试使用模板模板参数定义一个函数(我只想知道它是如何工作的)。我有以下几点:
template <typename T, template <typename> class Cont>
typename Cont<T>::iterator binary_search (typename Cont<T>::iterator first, typename Cont<T>::iterator last)
{
typename Cont<T>::iterator it;
// ...
return it;
}
然后在main ()
函数中:
std::vector<int> data;
// ....
std::vector<int>::iterator it = binary_search (data.begin (),data.end ());
尝试编译代码时出现此错误:
binary_search.cpp: In function ‘int main(int, char**)’:
binary_search.cpp:43:83: error: no matching function for call to ‘binary_search(std::vector<int>::iterator, std::vector<int>::iterator)’
我找不到任何适当的响应来帮助我解决此错误。任何帮助将不胜感激。
提前致谢
您拥有的是非推导上下文,以及模板模板参数不匹配,即使上下文是可推导的。 std::vector
采用第二个模板参数,即分配器,该参数默认为 std::allocator
。
对于非推导上下文,T
永远无法推导,并且始终必须指定,typename
表明了这一点。有关血腥的细节,请参阅此问题。
相关文章:
- "error: no matching function for call to"构造函数错误
- 为什么类中的ostringstream类型的成员会导致";调用隐含删除复制构造函数";错误
- 尝试将unique_ptrs推送到向量时使用纯虚拟函数错误
- C++ OpenCV 卡尔曼滤波器构造函数错误
- C++:用户定义的显式类型转换函数错误
- C++ 合并字符串以'system'函数错误
- C++ wmain 函数错误时使用 Unicode
- 结构数组的构造函数错误,错误消息:没有构造函数实例与参数列表匹配
- C++ 中常量属性的初始化构造函数错误
- 线程 std::调用未知类型,无法专门化函数错误
- 表单显示对话框函数错误,并且不执行下面的语句
- 函数错误 C2059:语法错误:'>'不起作用
- STL向量上出现奇怪的复制构造函数错误
- C++ Visual Studio 重载函数错误:没有重载函数的实例与指定的类型匹配
- C++引用已删除函数错误
- 为什么通过带有文字编号的引用调用会出现"无匹配函数"错误?
- C++ 乘法定义的构造函数错误消息似乎错误
- 在 c++ 代码中将数组传递给函数错误
- FFMPEG avcodec_decode_video2函数错误代码
- 为什么我会收到转换函数错误