What happens if you make call "delete this;"?, C/C++ Programming

The code contains two built-in pitfalls. First one, if it executes in a member function for an static, extern or automatic object, the program will possibly crash as soon as the delete statement executes. There is not any portable way for an object to tell that it was instantiated on the heap, thus the class cannot assert that its object is correctly instantiated. Second one, while an object commits suicide this way, using program may not know about its demise. So far as the instantiating program is concerned, the object remains in scope & continues to exist although the object did itself in. Usually Subsequent dereferencing of the pointer can & does lead to disaster.

You must never do this. As compiler does not know whether object was allocated onto the stack or on the heap, "delete this" could cause a tragedy.

 

Posted Date: 3/16/2013 2:58:47 AM | Location : United States







Related Discussions:- What happens if you make call "delete this;"?, Assignment Help, Ask Question on What happens if you make call "delete this;"?, Get Answer, Expert's Help, What happens if you make call "delete this;"? Discussions

Write discussion on What happens if you make call "delete this;"?
Your posts are moderated
Related Questions
A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a string of t

What if one forget the [] when deleteing array allocated through new T[n]? A: All life comes to a disastrous end. It is the programmer's responsibility not the compiler's to

Simple program of c++: int main() {    int   bushels;    float dollars, rate;                 cout                 cin >> dollars;                 cout

Blanche has a fashion design company called BLB_Best_Clothing Pty. That she has just opened recently

Explain high-order and low-order bytes. - Numbers are written from left to right in decreasing order of significance. In the same way, bits in a byte of computer memory can be

Hello I''m new to programming, and I''m making now my 1st program. My question is how to put substr in textbox that question mark should be at the end of sentence? And 2nd question


Problem Write a program in C++ to read N numbers in an array, the user should be able to search a particular number in the array using sequential search algorithm. Writing a

C o n t r o l S t r u c t u r e s I t i s o f t h r e e t y p e s: 1 .    S e qu e n c e s t r u c t u r e 2 .

Explain about the Character Constants in c language? The character constant is a single alphabet and a single digit or a single special symbol enclosed within a pair of single