• ### Popular Now

• 13
• 15
• 27
• 9
• 9

#### Archived

This topic is now archived and is closed to further replies.

# Problems with my HasParent()

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

## Recommended Posts

Here's the problem: I'm writing my own doubly linked list (see here) and I have a boolean function in my CNode class called 'HasParent()'. This is supposed to come in handy during attachments/detachments, when I need to see if the node already has a parent. Seems logical enough, I think. This is how my HasParent() function goes:
	bool HasParent()
{
if(pParent != NULL)
return true;
else
return false;

} // end HasParent

The project compiles nicely but crashes upon execution. When I debug I'm pointed to the line "if(pParent != NULL);" This may have to do with one of my Attach, AttachTo, or Detach functions. I was never good at debugging (btw, if anyone could point me to some helpful resources online). If my entire CNode code would be of any help, here is the link again: here). Please, any help you can provide. Thanks in advance. // "Programmers don't byte, they nibble a bit." // chimaera [edited by - chimaera on April 1, 2003 5:12:23 PM] [edited by - chimaera on April 1, 2003 10:10:55 PM]

##### Share on other sites
If the problem occurs within an Attach() function, the node you''re passing is a NULL pointer. You can fix this with a line at the beginning of your Attach() function like so:

if (pNewNode == NULL)
return;

If it happens within the Detatch() or AttatchTo() functions, the node is somehow getting deleted before it''s finished.