I have a struct like this:
class Items
{
private:
struct item
{
unsigned int a, b, c;
};
item* items[MAX_ITEMS];
}
You need to call delete
before setting it to NULL. (Setting it to NULL isn't required, it just helps reduce bugs if you accidentally try to dereference the pointer after deleting it.)
Remember that every time you use new
, you will need to use delete
later on the same pointer. Never use one without the other.
Also, new []
and delete []
go together in the same way, but you should never mix new []
with delete
or new
with delete []
. In your example, since you created the object with new
(rather than new []
which would create an array of objects) you must delete the object with delete
(rather than delete []
).