你的意思是什么? ChrisStrange, I changed your comparison function to:bool operator() (const It& lhs, const It& rhs) const {and it worked fine...Did you mean something else?Chris Chris Jefferson写道:Chris Jefferson wrote:您的比较运算符已经通过已取消引用的迭代器,而不是迭代器本身。 Your comparison operators gets passed already-dereferenced iterators, not the iterators themselves. 你的意思是什么?在大多数情况下,对于int * 的类型定义是不是在Into?至少这是我的实施。所以: bool operator()(它是lhs,它是rhs){ 返回Pred()(* lhs,* rhs); } 转换为: bool operator()(int * lhs,int * rhs){ 返回Pred()(* lhs,* rhs); } 我看不出有什么问题。 - Matthias KaepplerWhat do you mean? Isn''t IntVecIt in most cases just a typedef for int*anyway? At least it is on my implementation. So:bool operator() (It lhs, It rhs) {return Pred() (*lhs, *rhs);}translates to:bool operator() (int* lhs, int* rhs) {return Pred() (*lhs, *rhs);}I can''t see what''s wrong with that.--Matthias Kaeppler Matthias Kaeppler写道:Matthias Kaeppler wrote: Chris Jefferson写道: Chris Jefferson wrote:你的比较运算符已经通过已经解除引用的迭代器,而不是迭代器本身。 Your comparison operators gets passed already-dereferenced iterators, not the iterators themselves. 什么你的意思是?在大多数情况下,无论如何都不是int * 的typedef吗?至少这是我的实施。所以: What do you mean? Isn''t IntVecIt in most cases just a typedef for int* anyway? At least it is on my implementation. So: 这不是我的实现(gcc 3.3.3)。假设它是一个很大的 no-no! 然而,您可以将迭代器赋予向量< int>做& *它并得到一个 int *。我不肯定这是标准的保证,我记得 看到有关它的缺陷报告,不记得它是否被接受。 我'从来没有见过没有工作的实施。 ChrisIt isn''t on my implementation (gcc 3.3.3). Assuming that it is is a bigno-no!You can however given an iterator into a vector<int> do &*it and get anint*. I''m not positive this is guaranteed by the standard, I rememberseeing a defect report about it and can''t remember if it got accepted.I''ve never seen an implementation where it didn''t work.Chris 这篇关于通用间接适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 01:34