This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: std::vector<T>::const_reverse_iterator
- To: dhoover at acm dot org
- Subject: Re: std::vector<T>::const_reverse_iterator
- From: Benjamin Kosnik <bkoz at redhat dot com>
- Date: Wed, 18 Jul 2001 11:23:32 -0700 (PDT)
- cc: libstdc++ at gcc dot gnu dot org
> 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.