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
within 2 mins give me answer pllzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

Task 1 Demonstrate a Java client and server exchanging one text message in each direction. Task 2 Demonstrate a C client and server exchanging one text message in each

1) Database: The database needs to be used for persistent storage of cars. For details of what information should be stored in the database, please see the description above. You

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

A container class is a class which is used to hold objects in external storage and memory. A container class work as a generic holder. A container class contains a predefined behav

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Deliverables: you are required to upload your c code in the assignment dropbox set in Moodle. You are supposed to work with Linux gcc compiler and pico editor for compiling via the

want the codings for these topic in ur experts minds.com

how to get plus asterisk pattern

i didnt no how to write and how to implement and the programming can be done in C and execution should be done in UNIX