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

Const char *p , char const *p What is the difference between the above two?

650


Explain about vectors in c ++?

589


Why Pointers are not used in C++?

614


How important is c++?

522


What things would you remember while making an interface?

556






Where Malloc(), Calloc(), and realloc() does get memory?

601


What is the difference between an enumeration and a set of pre-processor # defines?

824


Why we use #include iostream in c++?

565


What is split a string in c++?

685


What is token c++?

568


Explain how to initialize a const member data.

592


What does int * mean in c++?

627


Can we inherit constructor in c++?

580


Define stacks. Provide an example where they are useful.

570


what is C++ objects?

661