没有忘记任何事情)。 forward_iterator只是变量的名称:) that''s because, if you see the documentation for the class vector, youwill discover that the vector iterator is a random iterator, that is, itimplements the operators ++, --, ==, &, <, +=, -=, +, -, [] (if Ihaven''t forgot any). forward_iterator is just the name of your variable :) 不需要它。例如,如果他们告诉你函数 模板< typename iterator> foo(iterator i); 需要一个双向迭代器,这是因为在foo内部将使用 运算符++和 - 。如果你提供了一个前向的迭代器,编译器会抱怨,而不是找到任何操作符 - 对于 那个类。 it''s not needed. For example, if they tell you that the functiontemplate<typename iterator>foo(iterator i);requires a bidirectional iterator, it''s because inside of foo both theoperators ++ and -- will be used. If you provide it with a forwarditerator, the compiler will complain, not finding any operator-- forthat class. 我有点困惑。如果前向 迭代器只是变量名,编译器会如何抱怨?我可以让它报告 错误的唯一方法是,如果我创建自己的类class ForwarIterator我不知何故 使用 - 是非法的。 I am a bit confused. How will the compiler complain if a forwarditerator is just a variable name? The only way I can get it to report anerror is if I make my own class "class ForwarIterator" where I somehowmake it illegal to use "--". 这篇关于如何保证迭代器的行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 12:50