What will happen if when say delete this ?

Answer Posted / hitout

There are different cases to this
1) If the memory is allocated in stack, delete this should
not be called since it calls destructor twice.
2) delete this can be called in all functions except
destructor if the memory is allocated on heap(ie if new
operator is used and the object is not explicitly deleted).

3) Delete this in destructor will always cause an infinite loop.

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What data encapsulation is in c++?

585


How can you link a c++ program to c functions?

613


Why do we need c++?

589


What is dev c++ used for?

599


When do we use copy constructors?

589






What is c++ manipulator?

545


How delete [] is different from delete?

585


What is std namespace in c++?

715


What is buffer and example?

517


Comment on assignment operator in c++.

697


How a pointer differs from a reference?

684


What is the purpose of ios::basefield in the following statement?

779


write a function signature with various number of parameters.

555


Can we make copy constructor private in c++?

587


What is a syntax in c++?

599