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

Explain about the Integer constants in c language? An integer constant is the integer valued number and it refers to a sequence of digits. A decimal integer constant includes o

write a program to find the area under curve y=f(x) between x=a and x=b,integrate y=f(x) between the limits a and b

#include stdio.h> #include conio.h> #include string.h> void main() {           int i=0,j=0,k=0,l=0;           int a[3][3],temp[3][3];           clrscr();

Depreciation to a salvage value of 0. For tax purposes an item may be depreciated over a period of several years, n. With the straight line method of depreciati

Explain the Command Line Parameters? The Command line arguments are parameters supplied to a program from the operating system. These arguments are parameters accepted to main

(a) Define a procedure (deep-member x e) that takes a list x and an element e and returns #t if the element e is in the list or in any lists that the list x contains. e.g., (dee

Define the Bitwise Operators in c language? C has distinction of supporting special operators that known as bit wise operators for manipulation of data at bit level. These oper


Question 1 Write a program that accepts a 3x3 matrix from the user and finds the transpose of it Question 2 Explain Brief about class and objects. Also describe friend functi