home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!rational.com!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Subject: Re: Is it possible to use 'delete this' ?
- Message-ID: <rmartin.726675168@thor>
- Sender: news@rational.com
- Organization: Rational
- References: <rmartin.725129268@thor> <BzqE5s.6Lr@comp.vuw.ac.nz> <rmartin.725581109@thor> <C000qE.D3J@comp.vuw.ac.nz>
- Date: Sun, 10 Jan 1993 14:12:48 GMT
- Lines: 32
-
- robertd@kauri.vuw.ac.nz (Robert Davies) writes:
-
- |The problem I had with Bob's first reply was that he didn't answer the
- |question: is "delete this" legal.
-
- To my knowledge, the syntax is legal. (Steve Clamage: Can you
- comment on legality?)
-
- |Then it would be appropriate to give a warning. Incidentally, is the warning
- |about is causing difficulty to some compilers just a "gut feeling" or are
- |there specific examples?
-
- No specific examples. I give the warning because I have seen no words
- in the ARM to the effect that the code generated by the compiler must
- assume that the object may not exist during a member function call.
-
- |Bob's warning about "delete this" seems to apply to any use of "delete" by
- |an entity that didn't do the corresponding "new". Otherwise there is always
- |the risk that the "delete" will be applied to something not created by
- |"new". Is this another safe programming rule?
-
- No. And my warning is only about the dangers of "delete this".
- "delete this" can only be appropriate for objects that are "always"
- allocated from the heap. Unfortunately, there is no way for an object
- to insure this.
-
-
- --
- Robert Martin Training courses offered in:
- R. C. M. Consulting Object Oriented Analysis
- 2080 Cranbrook Rd. Object Oriented Design
- Green Oaks, Il 60048 (708) 918-1004 C++
-