Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!caen!spool.mu.edu!uunet!godzilla!kohlrabi!robert From: robert@kohlrabi.tcs.com (Robert Blumen) Newsgroups: comp.lang.c++ Subject: Re: Object pointers, and destructors Message-ID: <2289@godzilla.tcs.com> Date: 31 May 91 22:59:58 GMT References: <19944@sdcc6.ucsd.edu> Sender: root@tcs.com Reply-To: robert@kohlrabi.tcs.com (Robert Blumen) Distribution: comp Organization: Teknekron Communications Systems Lines: 30 In article <19944@sdcc6.ucsd.edu>, cs162sbj@uape_5.ucsd.edu (....What Is?....) writes: |> [1] |> I want to be |> able to control pointer assignments the way I can control object |> assignments, but I haven't been able to overload operators using |> pointers to objects, just objects. How is what I want to do |> accomplished cleanly? Perhaps you can do what you want by overload the per-class operator new, operator delete, and operator &. You can also define pointer objects that have the desired semantics (most generically done using templates) and use the pointer objects rather than regular pointers for the classes that need ref counts. |> [2] Why doesn't delete() automatically set the original pointer to |> NULL? I can't do it from within my destructor, and I can find no |> reason to leave it pointing to freed memory. |> You could do this yourself by writing your own ::operator delete and linking it into your code. I can't say just why it doesn't do this, since not doing so means that the post-delete pointer value is certainly invalid. It is consistent with the C++ philosophy "it doesn't work this way by default but you can do it yourself" ----------------------------------------------------------------------------- Robert Blumen | rblumen@tcs.com Senior Software Engineer | 2121 Allston Way, Berkeley, CA 94704 Teknekron Communications Systems, Inc. | (415) 649-3759