![]() |
VOOZH | about |
Ideally delete operator should not be used for this pointer. However, if used, then following points must be considered.
1) delete operator works only for objects allocated using operator new (See this post). If the object is created using new, then we can do delete this, otherwise behavior is undefined.
2) Once delete this is done, any member of the deleted object should not be accessed after deletion.
0
The best thing is to not do delete this at all.
Thanks to Shekhu for providing above details.
References:
https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP05-CPP.+Avoid+deleting+this
https://en.wikipedia.org/wiki/This_%28computer_science%29