Yeah you really do have to make sure that they are initialised to NULL at some point. How you do that depends on the real code of yours though. If they're member variables, use a constructor initializer list. If gobals, assign NULL in the declaration. I was once told strictly to always initialise my variables, even though I was using a language and compiler that always did that. It's advice you come to share after a while.
Originally Posted by josephjah
Oh of course, that is a real word, I almost forgot. Still in the context of C++ code it is fingernails on a blackboard for many people. Much safer to stick with 'destruct' all the time.
tr.v. de·con·struct·ed, de·con·struct·ing, de·con·structs
1. To break down into components; dismantle.
It isn't a spelling error, just used a different word at the time, and it stuck.
Sorry, didn't mean to be hard on you. Some of us just like to be thorough.
*sighs* Sorry.. After eliminating several hundred lines of unrelated code, variables, and definitions, I left a stray var. Oh well.
You can use a std::list in two ways.
Well, I am using my LL code to attach different types of objects to each node which may themselves contain anything from strings to longs, to links to entirely different sublists.
I guess I could probably use it by just storing pointers to each newly created object in the list and then referencing them that way... But I would rather have this worked out because now I am curious... but it seems no one knows why it is behaving in such a strange way..
Each node contains a pointer to your struct and a pointer to the next/prev nodes, or
Each node is essentially a structure that contains your struct as one of the members and the next/prev pointers as other members.
The later means that the memory allocation/deallocation is handled entirely with/by the list itself. The former means you allocate what the node points to and you delete it later.
Usually you would use the second method and store the object directly in the list. E.g. std::list<string> for a list of strings.
But if the list doesn't own the object (maybe this is just a sublist and they ALL appear in a different list anyway), then you use std::list<string*>
Still it's a good experience to write your own list, so I'd suggest keeping at it until it is sorted anyway. Well done sticking at it so far.:)