Of course you did something wrong. Lines 10 and 11 result in undefined behavior. Undefined behavior is something you absolutely do not want in your program.
Cire, I really appreciate your help!! I'm not entirely sure what is causing the problem. Here is the full code I have so far. I was merely doing my own tests on my implementation when I ran into the undefined behavior. I hope it is easy enough for you to read.
Nothing is hard about it. I'm not sure why you are being so terse.
I am teaching myself from books and was doing my own bit of testing. I guess I had the misconception that delete actually cleared the memory location. Since apparently it does not, it seems that it just releases it to be used at some other point later on. Therefore, since nothing else has happened the object is still in memory at that location and the program added a node to it, which would not always happen (incidental). I did not plan on trying to use the object again, it was more of just a "what happens if I put this code here". When it actually worked it threw me for a what the fortran moment.
On a side note, what do you think of everything else?? Comments/Critiques
On a side note, what do you think of everything else?? Comments/Critiques
The data members of your linked list class should not be public. iterator should not be a member at all. You need a copy constructor and copy assignment operator. Client code should not be worried about how you're storing the data internally so member names like addNode would better off without the Node reference. There is no reason for you to use dynamic memory in main. You should get into the habit of using initialization lists in constructors:
The implementation/logic is fairly solid thus far, but it's lacking much of the functionality one would expect of a linked list. You've also done of a fair job of keeping functions small and focused, which I don't see too much of at your level.
Overall, I'd say you've done a good job and are on the right track.
Thanks. I was aware I still needed a copy constructor and copy assignment operator along with the ability to sort, etc..., I just haven't gotten there yet (I took a break to watch the Red Wings game).
As for using dynamic memory in main(), I was merely just doing it for testing purposes. The whole program was more about setting up the class structure instead of actually doing something. The main() was merely just to utilize it and by using dynamic memory I could call delete to make sure my destructor was deleting each node.
I did not know about initialization lists in C++...THANK YOU!!
My plan is to setup the linked list just using an integer data type in the node for now and then my next project is to convert it to a template.