c++ - 错误 'no match for call to vector<int> normal_iterator<int*, vector<int>>::difference_type)'

标签 c++ vector iterator shuffle

我正在尝试使用这个 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 as r(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/

相关文章:

c++ - 上传 .csv 或 .txt 文件以填充 QTableView

C++ 使用 std::vector 迭代类指针

c++ - c 是否优化了 for 循环的检查部分?

c++ - DialogBox 消息是否发送到自定义消息循环?

c++ - C++中的 map 数据结构

c++ - 初始化多对象双端队列<vector<vector<float>>>

php - 是否有使用生成器充当迭代器的接口(interface)?

iterator - 在 Go 中创建迭代器最惯用的方法是什么?

java - 迭代时向 HashSet 添加元素

c++ - avl树中删除过程的实现