Undefined behavior from C++ vector [Answered]

Правка en2, от Walid_Amin, 2016-08-21 18:17:14

UPD: It was answered in Errichto's comment

I was coding a build function for persistent segment tree using vectors and I am getting Runtime error.

I replaced vector with array and it passes.

The code is just a few lines.

Code using vector (State: gives Runtime error): http://ideone.com/2c5tec

Code using arrays (State: Okay): http://ideone.com/WxBwJJ

I spent hours trying to spot the bug in the code and I removed all the code which is irrelevant to the bug to make it more simple to debug.

What really makes it more weird is when i removed those: "v[p].l=" and "v[p].r" it runs okay, here is it: http://ideone.com/alzUxP (State: Okay)

I will appreciate it very much if anyone told me why it keeps giving RTE.

Thanks very much.

Теги c++, vector, undefined behavior

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский Walid_Amin 2016-08-21 18:17:14 137 Tiny change: ':Errichto] [comment]' -
en1 Английский Walid_Amin 2016-08-21 18:03:43 743 Initial revision (published)