Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!think!snorkelwacker!apple!portal!cup.portal.com!wmmiller From: wmmiller@cup.portal.com (William Michael Miller) Newsgroups: comp.lang.c++ Subject: Re: operator delete -- static AND virtual ???? Message-ID: <30161@cup.portal.com> Date: 24 May 90 00:48:06 GMT References: <401@mole-end.UUCP> <29839@cup.portal.com> <413@mole-end.UUCP> Organization: The Portal System (TM) Lines: 47 mat@mole-end.UUCP (Mark A Terrbile) writes: > when I write > > delete xp; > > I am invoking a delete operator. Aha, here's part of the problem. There is a difference between the delete operator and operator delete(). The definition of the delete operator is that it invokes the destructor, if any, and then invokes operator delete(). This unfortunate overlapping of terminology is bound to be confusing, but it's too late now to fix it. (I've been told that originally destructors were member functions named "delete()" instead of ~classname(); that would have been preferable from several perspectives. Not only would it have avoided this particular confusion, but it would have made virtual destructors work like other virtual functions -- virtual destructors are the only virtual functions for which the name of the overriding function is *different* from the name of the base class function!) > The effect is that the delete operator that is invoked depends upon the actual > type of the complete object, and that is the behavior which I usually expect > of a virtual function. You're absolutely right on this point; I didn't catch it from your original posting. The fact that you may end up invoking a derived class operator delete() even though you used a base class pointer for the delete operator is *not* spelled out in the manual, and a clear statement of this fact (or the contrary, although I think most would agree with you about the desirability of this behavior) is definitely needed. Thanks for pointing that out. > The exact words of the reference manual are that operator delete is static. In some sense, calling operator delete() "static" is arbitrary and a bit misleading; the only thing operator delete() has in common with static member functions is the absence of a "this" pointer. The main idea of static member functions is that they can be invoked by the classname::member() syntax, i.e., without referring to a particular object, but that makes no sense for operator delete(): it has to be accessed via an object, although the object will have been destroyed before operator delete() gets control. I think X3J16 may want to visit this issue of terminology as well. Sorry for missing part of your meaning the first time 'round. -- William M. (Mike) Miller, Glockenspiel, Ltd. wmmiller@cup.portal.com