нет ошибки вызова соответствующей функции при использовании std :: find - PullRequest
0 голосов
/ 24 сентября 2018

У меня есть следующая функция (для тестирования):

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, что я не могу вывестиили след ...

Любая помощь приветствуется!

Ответы [ 3 ]

0 голосов
/ 24 сентября 2018

В сообщении об ошибке нет find от #include <algorithm>, только от streambuf_iterator.h.Добавить #include <algorithm>.

0 голосов
/ 24 сентября 2018

Я думаю, что вы забыли включить <algorithm>

Пожалуйста, добавьте это #include <algorithm>

0 голосов
/ 24 сентября 2018

Вы возвращаете итератор, но объявление вашей функции 'void'

...