From 5101273267471872475 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,176c9dc06a6729eb X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 2002-04-04 16:15:07 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail From: "nmtop40" Newsgroups: comp.std.c++ Subject: Re: why doesn't delete NULL the pointer? Date: Fri, 5 Apr 2002 00:14:29 GMT Approved: Fergus Henderson , moderator of comp.std.c++ Message-ID: <3cacea0c$1@news1.homechoice.co.uk> References: X-Trace: mail2news.demon.co.uk 1017965674 mail2news:12206 mail2news mail2news.demon.co.uk X-Complaints-To: abuse@demon.net X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Original-NNTP-Posting-Host: 10.16.18.213 X-Original-Trace: 5 Apr 2002 01:04:28 GMT, 10.16.18.213 Lines: 39 Xref: archiver1.google.com comp.std.c++:10396 On the rare occasions when you want it set to NULL (0) you can do that yourself, can't you? You could write something like this: template < typename T > delete_and_null( T*& ptr ) { delete ptr; ptr = 0; } template < typename T > delete_and_null_array( T*& ptr ) { delete [] ptr; ptr= 0; } Note that I have actually come across a real example where, even using a smart-pointer, I wanted to set a pointer to 0 when its last reference was deleted. That is because I had a singleton model where you could only have one live object at a time, but that had a limited lifetime, and was deleted when its last reference disappeared, but which could later be re-created. To see partly how I did it, look at my own smart-pointer template at http://www.nmtop40.com/CodeBase/SmartPtrT.h (look at the second RefCountImpl class). (Sorry if this has gone slightly off-topic). --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]