Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!julius.cs.uiuc.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!rutgers!mcnc!xanth!cs.odu.edu!zeil From: zeil@cs.odu.edu (Steven J. Zeil) Newsgroups: comp.lang.c++ Subject: Re: Book of the Week Club Message-ID: <1990Nov29.172517.3695@cs.odu.edu> Date: 29 Nov 90 17:25:17 GMT References: <59405@microsoft.UUCP> Sender: usenet@cs.odu.edu (Usenet News Poster) Reply-To: zeil@cs.odu.edu (Steven J. Zeil) Organization: Old Dominion University, Norfolk, VA Lines: 16 Nntp-Posting-Host: dolphin.cs.odu.edu In article <59405@microsoft.UUCP> jimad@microsoft.UUCP (Jim ADCOCK) writes: >Be forwarned however that in his ref counted pointer class he makes the >common mistake of decrementing the old referenced object before incrementing >the new referenced object. This has the effect of possibly prematurely >deleting the old referenced object when it is the same object as the newly >referenced object. Probably the best fix is just to explicitly test against >the possibility that the old and new objects are the same. Actually, that fixes only a special case of the general problem. Suppose that A points to B, B points to C, and I try to replace the pointer in A to make it point to C. This passes your proposed test, but decrementing B's count before incrementing C's could result in both B and C being deleted, when in fact only B should have been deleted. Steve Z