Possible duplicates:
C ++: Delete this?
Object-oriented suicide or remove it;
I learn C ++ by reading the very good C ++ Primer book and I will learn how C ++ frees memory from a keyword deletesuch as C, c free. Java and Pascal do not have this mechanism for explicitly freeing memory. This can lead to errors in programs if they work for a long time, and the variables are destroyed, which is necessary so that it is not trivial.
In short, I wonder if it is legal or appropriate, for example, in C ++ for a variable to make this.delete()and delete itself. We mainly hear about the release of pointers to C and C ++, and this is done with new keywords freeand delete. Pascal also has pointers, but Java does not. Therefore, in Java, this should not be possible, since you do not explicitly delete objects, C has no objects, therefore, structcould not freeallocate memory, even if it was technically possible, since C has no objects and Pascal too.
So, I suppose that leaves C ++ for my question, is it legal for an object to delete itself with something like this.delete()?
source
share