I was wondering if it is safe to do this...
delete p_pointer;
p_pointer = p_otherPointer;
Rather than...
delete p_pointer;
p_pointer = 0;
p_pointer = p_otherPointer;
I would assume so since there aren't any new memory allocations between the deletion and assignment, but I just want to make sure.
Yes it is safe. It's useless to set the deleted pointer to NULL if you're about to reassign it anyway. The reason people set deleted pointers to NULL is so they can "mark" it as deleted, so later they can check if it has already been deleted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With