Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
How to improve this code
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Gavin Deane, post: 2543253"] Whether he compiled the code or not, Victor is correct. The code in question is list<int>::iterator t=p.begin(); if(i>n) return; for(int k=0;k<i;k++) { p.insert(t++,i); The first time this is executed, the list p is empty and so the iterator t is initialised to p.end() (which is the same thing as p.begin() for an empty container). Incrementing p.end(), as you do on the last line I have quoted, is undefined behaviour. Anything can happen, including exactly what you expect. I compiled and ran your code and the undefined behaviour manifested itself in a different way. The program crashed on that line. Purely because you were unlucky. Gavin Deane [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
How to improve this code
Top