Path: utzoo!attcan!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Objective suicide Message-ID: <276@taumet.com> Date: 28 Jun 90 15:26:48 GMT References: <685@dyndata.UUCP> Reply-To: steve@taumet.UUCP (Stephen Clamage) Organization: Taumetric Corporation, San Diego Lines: 19 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; } > /* ... */ > } Yes, but do be careful, as noted in your full example. I have done this in a class destructor, but would not do it in a normal member function. After the delete, there is no guarantee that the class data makes any sense, and in particular that the virtual table is intact! So a later destructor may try to operate with garbage. This is a particular worry with virtual destructors when the virtual table is trashed. -- Steve Clamage, TauMetric Corp, steve@taumet.com