std::vector<T>::const_reverse_iterator

Dean Hoover dhoover@rochester.rr.com
Wed Jul 18 10:30:00 GMT 2001


I just started using gcc-3.0 and found that the
code that follows will not compile:

#include <iostream>
#include <string>
#include <vector>

int main()
{
        std::vector<std::string> v;
        v.push_back("aaa");
        v.push_back("bbb");
        v.push_back("ccc");
        std::vector<std::string>::const_reverse_iterator iter;

        for (iter = v.rbegin(); iter != v.rend(); ++iter)
                std::cout << *iter << std::endl;
}


I get the following errors:

g++     foobar.cc   -o foobar
foobar.cc: In function `int main()':
foobar.cc:13: no match for
`std::reverse_iterator<std::__normal_iterator<const
   std::string*, std::vector<std::string, std::allocator<std::string> >
> >& !=
   std::reverse_iterator<std::__normal_iterator<std::string*,
   std::vector<std::string, std::allocator<std::string> > > >' operator
make: *** [foobar] Error 1

This problem does not occur when I change the const_reverse_iterator to
const_iterator and remove the leading 'r' from begin and end. I think
the
example with the reverse iterator should work. Am I wrong?

Dean Hoover



More information about the Libstdc++ mailing list