Hi,
Today I was writing some recursive code and it behaved in a very weird way and I couldn't find out why this happened,
Here is the code
It gives runtime error, and doesn't assign the values correctly!
However if I do it like this
Everything just works perfectly! I feel I'm missing something but I couldn't figure it out for over half an hour and yet the code is simple (I suppose).
It would be greatly appreciated if anyone could point out the problem.
Thanks!
You can't assign a vector element to a result of a function that changes the vector here is an example
the problem is
Got it ? it's not the same x[0] before and after the push , so you get in access violation runtime error .
I think I quiet understand, what is the reason of this? Maybe because it saves the address of that variable and then goes to evaluate the function so when it returns, this address no longer belongs to the vector?
exactly , that's the problem , [discover it barely :D] try it here
Great tool! First time to see it. Thanks a ton for answering you saved my day :D :D
You're welcome ;)