Not to create some misunderstandings here:
In MSVC, a NULL pointer is ALWAYS 0x00000000 !
Release build, debug build, hardisk upside down,
it's ALWAYS 0x00000000. No exceptions. Anything
else would be a horrible mess.
What you are expiriencing is an uninitialized pointer.
When you don't initialize a pointer, or don't set it to
a new value after you called delete on it, MSVC will
set it to a value like 0xcdcdcdcd to symbolize it has
no value. So you can see that a pointer is not
initialized instead of wondering why you program
crashes when you try to call a function on your
pointer 0x139abc87 which in reality is just a bunch
of random numbers.
So what you are getting at here is that you have a
pointer in your list that is either not initialized,
or has been deleted previously.
Code:
Character *dp = new Character;
while(fighting!=NULL) // erase this linked list
{
dp = fighting;
fighting = fighting->next;
dp->next = NULL;
delete dp;
}
Why does dp have to be a new Character, when the
first thing you do is lose it's value ( dp=fighting; ) ?
Another thing to check: Is the list always teminated
by an element that has NULL as a next value ?
Next Question: Is fighting INITIALIZED to NULL in your
constructor ? If not, it might fail at any instance in your
list.
Suggestion:
If you want to delete a list of classes, use this code:
Remember that when you call delete, the destructor
is called.
Code:
CCharacter::~CCharacter()
{
// this calls the destructor of the instance
// that is stored in fighting, which in turn
// will delete it's predecessors in it's own
// destructor
if( fighting != NULL ) delete fighting;
fighting = NULL;
}
Another thing that comes to mind: Make sure you have
each instance only once in this list.
Example:
A->B->C will be fine
A->B->A means trouble