foo.cpp: In member function `void Foo::bar()':
foo.cpp:13: error: no matching function for call to `distance(
__gnu_cxx::__normal_iterator<char*, std::vector<char, std::allocator<char> >
>, Foo::bar()::ConstIter&)'
because the compiler wants to call the non-const version of vector<char>::begin() since the member function bar() is not const, but the other parameter to std::distance() is a const_iterator and std::distance() of course wants two iterators of the same type. So apparently either there is no implicit conversion function from iterator to const_iterator or the compiler can't figure to call it. Anyway...
So, assuming that I cannot make the member function const for reasons far too complicated to go into here, does anyone have a slick way to solve the problem that is not either 1) change the const_iterator to iterator, or 2) use an obnoxious const_cast?
you could make another const_iterator variable to hold vec.begin(), but that's also inelegant. But sticking in a (ConstIter) isn't so bad. Don't need an actual const_cast.