home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: Dangling pointers & suggestions on future implementations of "delete"
- Message-ID: <1993Jan22.193322.20710@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <Jan18.210305.21697@yuma.ACNS.ColoState.EDU> <1993Jan19.193048.15022@borland.com> <1993Jan20.213807.20740@cbnewsi.cb.att.com>
- Date: Fri, 22 Jan 1993 19:33:22 GMT
- Lines: 30
-
- In article <1993Jan20.213807.20740@cbnewsi.cb.att.com> rhw@att.com (Robert Wentworth) writes:
- >In article <1993Jan19.193048.15022@borland.com> pete@borland.com (Pete Becker) writes:
- >>In article <Jan18.210305.21697@yuma.ACNS.ColoState.EDU> bb760597@longs.LANCE.ColoState.Edu (Blake Buhlig) writes:
- >>>I have been trying to find a way to overload the delete operator to set its
- >>>pointer argument to NULL. This would help prevent dangling pointer
- >>>dereferencing
- >
- >I agree: simply setting the deleted pointer to NULL or some illegal value
- >leaves a big hole because other pointers can still point to the same
- >now non-existent object.
-
- However, it is very useful to set a pointer to null after
- deleting it because then subsequent deletes will do no harm.
- Often, there is ONLY one pointer to each object.
- How about:
-
- template<class T>
- void destroy(T*& p){ delete p; p=0;}
-
- Note: 'delete' cant set its argument to 0 because the argument
- mightn't be an lvalue:
-
- delete p+1;
-
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;------ SCIENTIFIC AND ENGINEERING SOFTWARE ---ph: 2 799 8223 --------
-