• Advertisement
Sign in to follow this  

wierd linked list deletion problem

This topic is 1893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am having a weird problem were i have a linked list system that creates objects and it works fine until i add any numeric variable to the main loop then it crash when it is deleting the objects


[CODE]
while (1)//this deletes the objects
{
if (root->next != NULL)
{
temp=root->next;
delete root;
root = temp;
}
else
{
break;
}
}
[/CODE]


This next part is the beginning of the main loop it works fine until i added the variable "test" after i added it, it crashes whenever i try to delete the whole list using the code above.


[CODE]
int main()
{
int test = 0;
zombie master;
zombie *root = &master;
zombie *temp=NULL;
[/CODE]

Share this post


Link to post
Share on other sites
Advertisement
If [i]root [/i]in the second code is the same as the [i]root [/i]in the first code, then you should not call [i]delete [/i]on it because you didn't [i]new[/i] it. You [b]must not[/b] [i]delete[/i] what you didn't [i]new[/i]. Edited by Brother Bob

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement