Today, I have seen some legacy code. In the destructor there is a statement like "delete this
". I think, this call will be recursive. Why it is working?
I made some quick search on Y!, I found that if there is a need to restrict the user to create the stack object, we can make destructor private and provide an interface to delete the instance. In the interface provided, we have to call delete on this pointer.
Are there any other situations for using such statements?
See Question&Answers more detail:os