I wonder if this is a good way to do that to reset a pointer to null. I think so but I want to be sure. I work in basic C++ (not c++ 11; c++ 14, ...).
Example:
MyClass * myClass = new MyClass();
delete myClass;
myClass = NULL;
I thought the delete reset the pointer but actually, no. If the pointer has the value 0xb861708 after the "new", after the "delete" the value is always 0xb861708. The delete frees the memory but does not reset the pointer. The freed memory can therefore be used by the operating system but the pointer still points to the memory area. If after the delete we do myClass->SomeFunction(), it crashes (SIGSEGV) the program or worse the operating system.
That's why I used to reset pointers after a delete but wanted to know if that was the right way to do it.
Many thanks.
Jocelyn
Reset the pointer the right way after a delete.