我正在尝试使用这个 vector.h 函数:
random_shuffle(s.begin()+from+i,s.begin()+to,s);
发生此错误:
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_algo.h|5255|error: no match for call to '(std::vector<int>) (__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type)'|
有什么想法吗?提前致谢!
最佳答案
第三个参数为std::random_shuffle
(假设你在谈论那个,如果不是,请澄清你的问题)必须是一个
function object returning a randomly chosen value of type convertible to
std::iterator_traits<RandomIt>::difference_type
in the interval[0,n)
if invoked asr(n)
(来自 here ),不是 vector 。您可能打算使用该函数的两个参数变体:
random_shuffle(s.begin()+from+i,s.begin()+to);
另外,请注意 std::random_shuffle
已经过时了。你应该使用 std::shuffle
相反。
关于c++ - 错误 'no match for call to vector<int> normal_iterator<int*, vector<int>>::difference_type)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30157048/