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

Is c++ a good beginners programming language?

669


Why c++ is better than c language?

660


What is an overflow error?

716


What is meant by entry controlled loop?

737


Are php strings immutable?

670






What is the difference between a definition and a declaration?

659


Is there structure in c++?

679


What is an adaptor class in c++?

694


Why is c++ still popular?

682


What does catch(…) mean?

719


Explain static and dynamic memory allocation with an example each.

725


What is the use of structure in c++?

633


What are static type checking?

714


What are the uses of static class data?

737


Define a constructor - what it is and how it might be called (2 methods)?

693