gcc - 将 gcc vector::iterator 传递给函数有什么问题?

这在 MSVC 中编译得很好,但 gcc 提示。 The code on ideone .我不明白通过引用传递迭代器有什么问题。

错误

prog.cpp: In function ‘void FindType()’:
prog.cpp:8: error: no matching function for call to ‘FindType(__gnu_cxx::__normal_iterator<Var**, std::vector<Var*, std::allocator<Var*> > >, __gnu_cxx::__normal_iterator<Var**, std::vector<Var*, std::allocator<Var*> > >)’
prog.cpp:4: note: candidates are: void FindType(__gnu_cxx::__normal_iterator<Var**, std::vector<Var*, std::allocator<Var*> > >&, __gnu_cxx::__normal_iterator<Var**, std::vector<Var*, std::allocator<Var*> > >&)
prog.cpp:5: note:                 void FindType()
prog.cpp:8: error: return-statement with a value, in function returning 'void'

编码
#include <vector>
using namespace std;
class Var {};
void FindType(vector<Var*>::iterator&b, vector<Var*>::iterator&e){}
void FindType()
{
        vector<Var*> ls;
        return FindType(ls.begin(), ls.end());
}

最佳答案

传递 const 引用。 .begin() 和 .end() 调用返回右值。

修订:但是,正如您在下面的评论中所观察到的,如果 b 是 const 引用,则不能执行++b 。在这种情况下,您下面的想法似乎是最好的:按值传递该迭代器。

https://stackoverflow.com/questions/9777899/

相关文章:

ant - 如何在不使用 IDE(Netbeans 等)的情况下使用外部库编译 java 文件?

c# - 引用的.NET程序集中的解析类型

gcc - 使用arm-linux-gcc编译STLPort时发生未知错误

c# - 为什么尝试在WPF/C#中注册所有事件时出现构建错误?

database - 为Windows和Linux编译64位sqlite

iphone - 在编译应用程序时遇到这样的错误

objective-c - 初始化程序元素不是编译时常量错误

android - Maven不会因引入的编译错误而失败

visual-studio-2010 - XNA 4.0 Visual Studio 2010错误

ruby-on-rails - 编译错误,意外的 kENSURE,预计 Rails 3 项目中出现