2 Attachment(s)
Situation where deleting a pointer doesn't work, but setting it to NULL does?
I was working on a project for school where we had to generate a blackjack hand and do some tests. I've setup an array of pointers thats created for each card in the hand, to a max of 5. I have it setup in the default constructor to loop through and set all of the cards to NULL, and then in my addcard() function I create 'new' cards for each card that's NULL. Everything works great, one of the requirements was to have a clearHand() function that loops through and deletes each card in the array, my problem is that delete doesn't do what I expected it to do, but setting each card to NULL does.
So my question is, when would deleting a pointer cause a problem where setting it to NULL works instead? Am I creating the initial array wrong? I got 100% on the grade, and when i asked why it wasn't working he said not to worry about it, but I don't like to learn to do things the wrong way if I've done something wrong. (Learned a lot so far thanks to Grumpy and Elysia! :))
I can post the source if anyone wants to poke around and tell me what I did wrong.
Output using delete: Attachment 11434
Output using NULL: Attachment 11435