What happens when we make call "delete this;" ??

What happens when we make call "delete this;" ??

When we call "delete this" then two cases are generate in the code . First, if it executes in a member function for an extern, static, or automatic object, the program will probably crash as soon as the delete statement executes. There is no portable way for an object to tell that it was instantiated on the heap, so the class cannot assert that its object is properly instantiated. 

Second, when an object commits suicide this way, the using program might not know about its demise. As far as acc to the instantiating programme, the object remains in scope and continues to exist even though the object did itself in. Subsequent dereferencing of the pointer can and usually does lead to disaster.

By:Umang
Date:2006-01-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related C Subjective Links

C Subjective interview questions and answers for experienced and fresher