I have a pointer to an abstract class object ptr1
. I need to create another pointer with the same adress ptr2
so that when you free and zero the ptr1
pointer, the ptr2
also becomes zero.
SomeObject* ptr1 = new SomeObject();
SomeObject* ptr2 = ptr1;
delete ptr1;
ptr1 = nullptr; // after that ptr2 should be nullptr
I know that it's dangling pointers problem and it can be solved with smart pointers but I want to solve it without them. Thanks in advance for your help!