使用 std::find 时没有匹配的函数调用错误
no matching function call error using std::find
我有以下函数(用于测试(:
static bool foo(void)
{
std::string name = "name";
std::vector<std::string> test;
std::vector<std::string>::iterator vStart = test.begin();
std::vector<std::string>::iterator vEnd = test.end();
return (std::find(vStart, vEnd, name) == vEnd);
}
我收到一个编译错误:
/data/src/fiware-orion/src/lib/common/string.cpp: In function 'bool foo()':
/data/src/fiware-orion/src/lib/common/string.cpp:167:39: error: no matching function for call to 'find(std::vector<std::basic_string<char> >::iterator&, std::vector<std::basic_string<char> >::iterator&, std::string&)'
return (std::find(vStart, vEnd, name) == vEnd);
^
/data/src/fiware-orion/src/lib/common/string.cpp:167:39: note: candidate is:
In file included from /usr/include/c++/4.9/bits/locale_facets.h:48:0,
from /usr/include/c++/4.9/bits/basic_ios.h:37,
from /usr/include/c++/4.9/ios:44,
from /usr/include/c++/4.9/istream:38,
from /usr/include/c++/4.9/sstream:38,
from /data/src/fiware-orion/src/lib/common/string.cpp:31:
/usr/include/c++/4.9/bits/streambuf_iterator.h:369:5: note: template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(std::istreambuf_iterator<_CharT>, std::istreambuf_iterator<_CharT>, const _CharT2&)
find(istreambuf_iterator<_CharT> __first,
^
/usr/include/c++/4.9/bits/streambuf_iterator.h:369:5: note: template argument deduction/substitution failed:
/data/src/fiware-orion/src/lib/common/string.cpp:167:39: note: '__gnu_cxx::__normal_iterator<std::basic_string<char>*, std::vector<std::basic_string<char> > >' is not derived from 'std::istreambuf_iterator<_CharT>'
return (std::find(vStart, vEnd, name) == vEnd);
也许指向问题的消息是这样的:
template argument deduction/substitution failed:
但就我所理解的,find(( 函数参数(std::vector<std::string>::iterator
、std::vector<std::string>::iterator
和std::string
(中使用的具体类是清楚的。
特别让我惊讶的是,foo(( 函数的相同代码片段在我的代码的其他部分(即其他.cpp文件(中逐字工作,所以也许它以某种方式与#include
链相关,我无法推断或追踪......
欢迎任何帮助!
错误消息中没有来自#include <algorithm>
的find
,只有来自streambuf_iterator.h
的。添加#include <algorithm>
.
你正在返回一个迭代器,但你的函数声明是'void'
我想你忘了包含<algorithm>
请添加此#include <algorithm>
相关文章:
- C++模板类 - 继承调用错误的函数
- 使用 std::find 时没有匹配的函数调用错误
- C++命名空间中调用 void 函数的错误
- 使用成员初始值设定项列表时没有匹配的函数调用错误
- C ++尝试访问映射中的元素会给我一个不匹配的函数调用错误
- C++类静态成员函数调用错误
- 如何调查随机安卓原生函数调用错误?
- C++:函数调用错误:标识符"name"未定义,如果已定义?
- 复制构造函数调用错误
- 当我使用由unsigned int和unsigned long区分的重载函数时,引发了不明确的函数调用错误?这种重载有效
- 没有匹配的函数调用错误
- 虚函数调用错误的函数,在C++和Cocos2dX中的名称完全不同
- 纯虚拟函数调用错误
- 我的类出现函数调用错误
- 内联函数调用错误
- 函数调用错误
- 模板构造函数没有匹配函数调用错误
- 模板化成员函数调用g++错误:没有匹配的函数用于调用
- 模板函数调用错误503
- 擦除函数调用错误