This compiles fine in MSVC but gcc complains. The code on ideone. I don’t understand what is wrong by passing the iterators by reference.
The error
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'
The code
#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());
}
Pass const references. The .begin() and .end() calls return rvalues.
Revision: However, as you have observed in the comments below, you cannot do ++b if b is a const reference. Your idea below seems best in that case: pass that iterator by value.