Computer Science Canada auto_ptr can't maintain linked lists? |
Author: | HazySmoke)345 [ Mon Dec 24, 2007 4:19 pm ] | ||
Post subject: | auto_ptr can't maintain linked lists? | ||
First, thank you for reading this. A bet a lot of people would choose not to because of the subject. It does sound a bit advanced to most people I ask. The idea of a pointer that destroys the object automatically sounds interesting to me. I've enjoyed using linked lists in my programs ever since I fluked the previous Canadian Computing Competition with an array-out-of-bounds error. The only thing painful about linked lists is that the destruction process is quite tedious. The following program (I tried to make it as concise as possible, bear with me) attempts to create a linked list with 5 nodes. After successfully doing so, it will print out the text "done!". Whenever a node gets destroyed, the system will output "oh noes!"
I thought that this program will output one "done!" followed by five "oh noes!". This didn't happen. The program printed out what seemed like a million "oh noes!" before it crashed. Oh noes. Using my debugger, I found that the program is able to successfully keep the first node, but as soon as the second one goes in, everything goes wrong. Any help is appreciated, thanks. |
Author: | OneOffDriveByPoster [ Mon Dec 24, 2007 5:55 pm ] | ||
Post subject: | Re: auto_ptr can't maintain linked lists? | ||
HazySmoke)345 @ Mon Dec 24, 2007 4:19 pm wrote:
|
Author: | divad12 [ Tue Apr 01, 2008 7:38 pm ] |
Post subject: | Re: auto_ptr can't maintain linked lists? |
Particularly for contests, you should just use the STL. It has many containers (vectors, lists, maps) and useful methods that will save you a lot of time. |