Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map Iterator working for begin() but not for rbegin()

I have some class called Order. For some reason, the following code won't compile while using rbegin(), but it works for begin(). Is there a problem in the way I'm declaring the iterator or perhaps a problem with my pointer reference?

map<double, list<Order*>> m
typedef map<double, list<Order*>>::iterator iter;
iter iterator;

iterator = m.rbegin(); // this only works for m.begin()

Thank you!

like image 988
ch-pub Avatar asked Dec 14 '25 01:12

ch-pub


2 Answers

rbegin() returns a reverse_iterator, not an iterator.

like image 109
Steve Howard Avatar answered Dec 16 '25 17:12

Steve Howard


The types returned from begin() and rbegin() are different:

  • begin() returns std::map<K, V>::iterator
  • rbegin() returns std::reverse_iterator<std::map<K, V>::iterator>
like image 32
Dietmar Kühl Avatar answered Dec 16 '25 17:12

Dietmar Kühl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!