Say I wanted to “delete” an element, for example:
elements [5] = NULL;
I don't know much about Visual Basic, but it smells like the Visual Basic programming idiom, since "Set a = None" (or Null, I'm not sure) will delete the object that it points to (or, rather, decrease its reference count, for COM- objects).
As someone else noted, you should use either:
delete items[5]; items[5] = newContent;
or
delete items[5]; items[5] = NULL;
After delete[5] only possible use of the pointer stored in items[5] is causing problems. The worst part is that this can happen from the very beginning, and only start crashing when you allocate something else in the space previously used by *items[5] . These are the reasons that make C / C ++ programming “interesting,” that is, really annoying (even for those who love C, like me).
Writing only delete items[5]; preserves what might be a useless record, but it's a premature optimization.
Blaisorblade Jan 12 '09 at 1:50 2009-01-12 01:50
source share