【发布时间】:2020-02-18 08:08:04
【问题描述】:
我有这个代码:
#include <cctype>
#include <algorithm>
int main()
{
std::string str("ABCD");
std::all_of(str.begin(), str.end(), ::isxdigit);
return 0;
}
std::all_of 需要一个谓词作为最后一个参数。我要传递的是std::isxdigit。当我将它作为::isxdigit 传递时,它工作正常,但是当我使用std 传递它时,比如std::isxdigit,我得到了这个错误 :
12:58: error: no matching function for call to 'all_of(std::basic_string<char>::iterator, std::basic_string<char>::iterator, <unresolved overloaded function type>)'
12:58: note: candidate is:
In file included from /usr/include/c++/4.9/algorithm:62:0,
from 6:
/usr/include/c++/4.9/bits/stl_algo.h:508:5: note: template<class _IIter, class _Predicate> bool std::all_of(_IIter, _IIter, _Predicate)
all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
^
/usr/include/c++/4.9/bits/stl_algo.h:508:5: note: template argument deduction/substitution failed:
12:58: note: couldn't deduce template parameter '_Predicate'
为什么会出现此错误? 如果它是标准的,那么用 std 前缀传递它有什么问题?
【问题讨论】:
-
这能回答你的问题吗? stackoverflow.com/questions/6658767/…
-
重新打开:给定的关闭副本 (stackoverflow.com/q/6658767/1741542) 大约是
using namespace std。这不是这里的情况。