Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!news.cs.indiana.edu!noose.ecn.purdue.edu!gorilla.ecn.purdue.edu!helz From: helz@gorilla.ecn.purdue.edu (Randall A Helzerman) Newsgroups: comp.lang.c++ Subject: an object killing itself. Message-ID: <1991Jun9.080138.2540@noose.ecn.purdue.edu> Date: 9 Jun 91 08:01:38 GMT Article-I.D.: noose.1991Jun9.080138.2540 Sender: root@noose.ecn.purdue.edu (ECN System Management) Organization: Purdue University Engineering Computer Network Lines: 35 Hey net.c++.wisepersons... I have an application where it would be very convenient for a member function to be able to do the equivelent of deleting the object it is a member of, as shown in the following code: -------cut-here------------------------------------------ #include class depressed{ int i; public: hara_kiri(){ printf("Goodbye Cruel World....BANG!!!\n"); delete this; printf("thunk!\n"); } }; depressed *b; main(){ b=new depressed; b->hara_kiri(); printf("Back in the main program.\n"); } ----cut-here------------------------------------------ Is this OK? I never reference any data from the object again--I simple want the return from the member function hara_kiri() to go as planned. Would it still be OK if hara_kiri(), instead of deleting the object itself, called another function which deleted the object? Thanks in advance for wadeing through the code.