0
Working of the delete keyword
It says on here thst deleting a pointer pointing to some object of a class will destroy the object but thatāll only happen if the object is dynamically allocated right? Why would a normal object be destroyed if we delete a pointer pointing to it?!? Wonāt just the pointer be deleted, and the object still stay there?
3 Answers
+ 12
To see the full article from MSDN (which Apoorva fetch the information from there) see:
[https://msdn.microsoft.com/en-us/library/h6227113.aspx]
+ 7
WhenĀ deleteĀ is used to deallocate memory for aĀ C++Ā class object, the object's destructor is called before the object's memory is deallocated (if the object has a destructor). If the operand to theĀ deleteĀ operator is a modifiable l-value, its value is undefined after the object isĀ deleted.
+ 2
The delete operator takes a pointer to a primitive or an object. Without a pointer, it wouldn't know what to delete. They can be overloaded, so it doesn't necessarily have to be real dynamic memory.