quote:
You should set your pointer to NULL when you initialise it so that you can tell if it's valid later on. You can then check the validity of the pointer before you attempt to delete it.
ie:byte *pData=NULL;ProcessData (&pData);// code that's not important for this question.if (pData!=NULL) { delete [] pData; pData = NULL; }
quote:
Wrong. You can delete null pointers. You set pointers to null to make sure that delete knows not to, well, delete it. The following code will work just fine:
I stand corrected. I hadn't noticed that delete checks for null pointers because I've got into the habit of always checking pointers are valid before I do anything with them.
But anyway, the point [edit: that's not supposed to be a pun] is that he should set the pointer to NULL when he initialises it so that he can check its validity before he uses it.
____________________________________________________________
www.elf-stone.com
[edited by - benjamin bunny on August 12, 2002 7:22:10 AM]