This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: std::vector<T>::const_reverse_iterator



> 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]