pshishod2645's blog

By pshishod2645, history, 3 months ago, In English,

I am getting a very strange bug in my code for today's round problems B1, 2.

At a moment, I'm having a set of pairs.

[s]: {(1, 1), (1, 4), (1, 5), (1, 9), (1, 10), (2, 2), (2, 7)}

Then I'm accessing the last and second last element. (line 51-54 in mycode)

it = s.rbegin();  // prints *it = (2, 7)
it--; 
// prints *it = (1, 10)

But for some weird reason it jumps off (2, 2) and I'm unable to figure out why.

Any help will be appreciated.

 
 
 
 
  • Vote: I like it
  • +6
  • Vote: I do not like it

»
3 months ago, # |
Rev. 2   Vote: I like it +20 Vote: I do not like it

Since it is a reverse iterator, it++ should yield the second last element instead, and it-- will make it invalid, and dereferencing that is UB.