std::vector<T>::const_reverse_iterator

Benjamin Kosnik bkoz@redhat.com
Wed Jul 18 11:23:00 GMT 2001


> 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

Right. This operator

std::vector::const_reverse_iterator != std::vector::reverse_iterator

Does not exist. Thus, the message.

std::vector<std::string> v;
std::vector<std::string>::const_reverse_iterator iter;

for (iter = v.rbegin(); iter != v.rend(); ++iter)
                                ^^^^^^^^

because v is non-const, this version of rend() is called:

reverse_iterator rend();

You want

const_reverse_iterator rend() const; 


> This problem does not occur when I change the const_reverse_iterator to
> const_iterator and remove the leading 'r' from begin and end.

Right. Look at the signatures.



More information about the Libstdc++ mailing list