Is this safe and correct? I mean does the delete care only about the address it is given or is it important to delete the original pointer variable?
myClass *p1 = new myClass();
myClass *p2 = p1;
delete p2;
p1 = NULL;
p2 = NULL;
Delete only cares about the address, so your code is perfectly legal.
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