What will happen if when say delete this ?

Answer Posted / hemant

There are two scenarios:

1. Using "delete this;" in destructor

Here the call will be a recursive call to the destructor
infinitely. So the program hangs here.

2. Using "delete this;" in other members of a class
including constructor.

In this case, the call is a sucide call since the object
tries to delete itself which is nothing but sitting in a
space and destroy that space itself. That is definitely a
memory crash.

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can a Structure contain a Pointer to itself?

695


How can you specify a class in C++?

895


How to declare a function pointer?

676


If all is successful, what should main return a) 0 b) 1 c) void

657


Explain this pointer?

685






Differentiate between an array and a list?

813


Why is it necessary to use a reference in the argument to the copy constructor?

717


How does code-bloating occur in c++?

836


Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.

906


Explain the use of this pointer?

740


How do you import payscale data from non SAP to SAP?is it through LSMW or any other way is there?

3296


How can a called function determine the number of arguments that have been passed to it?

757


What is c++ good for?

683


Reads in the size of a square from the screen; 2. Prints a hollow square of that size out of “-“, “|” and blanks on screen; 3. Prints the same hollow square onto a text file. Your program should work for squares of all side sizes between 1 and 20. --- │ │ │ │ │ │ ---

1751


What is c++ code?

680