Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucsd!pacbell.com!ames!sparkyfs!mckenney From: mckenney@sparkyfs.istc.sri.com (Paul Mckenney) Newsgroups: comp.lang.c++ Subject: Re: Objective suicide Message-ID: <32393@sparkyfs.istc.sri.com> Date: 4 Jul 90 19:35:47 GMT References: <685@dyndata.UUCP> <276@taumet.com> <9299@cadillac.CAD.MCC.COM> <282@taumet.com> Reply-To: mckenney@itstd.sri.com (Paul E. McKenney) Organization: SRI International, Menlo Park, CA 94025 Lines: 25 In article <685@dyndata.UUCP> dan@dyndata.UUCP (Dan Everhart) writes: >Is it kosher for an object to delete itself? To wit: >class Obj > { > void Suicide () { /* ... */ delete this; } > } The following example appears on page 66 of Ellis and Stroustrup: void X::my_delete(Arena* a) { this->X::~X(); // explicit call of destructor if (a) a->free((void*)this); else delete (void*)this; } The text preceding the example says that my_delete is a virtual function (the class body for X is not shown). I presume that if there was no Arena parameter, it would be safe to allow the delete operator invoke the destructor (it has always worked for me... :-). Thanx, Paul