代码之家  ›  专栏  ›  技术社区  ›  fgalan

使用std::find时没有匹配的函数调用错误

  •  -1
  • fgalan  · 技术社区  · 7 年前

    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::string )很清楚。

    #include 在某种程度上我无法推断或追踪。。。

    3 回复  |  直到 7 年前
        1
  •  5
  •   Maxim Egorushkin    7 年前

    根本没有 find #include <algorithm> 在错误消息中,只有 streambuf_iterator.h . 添加

        2
  •  1
  •   Q-bertsuit    7 年前

    返回迭代器,但函数声明为“void”

        3
  •  1
  •   Rizwan    7 年前

    我想你忘了包括 <algorithm>

    #include <algorithm>

    推荐文章