wmmiller@cup.portal.com (William Michael Miller) (05/24/90)
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
turner@sp1.csrd.uiuc.edu (Steve Turner) (05/31/90)
In article <30161@cup.portal.com> wmmiller@cup.portal.com (William Michael Miller) writes: > ..., 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!) Virtual destructors *don't* work like other virtual functions - but not for the reason that you describe (Well... OK, that too.) Derived virtual dtors do not override the base class's dtor. Instead, they allow a pointer of type (Base *) to invoke the derived class's dtor, when passed to delete. Just wanted to clear that up - this is a small point, but one that several people seem to get wrong. -- Steve Turner (on the Si prairie - UIUC CSRD) ARPANET: turner@uicsrd.csrd.uiuc.edu UUCP: {ihnp4,seismo,pur-ee,convex}!uiucdcs!uicsrd!turner I went walking in the wasted city / Started thinking about entropy Smelled the wind from the ruined river / Went home to watch TV -- Warren Zevon
mat@mole-end.UUCP (Mark A Terribile) (06/01/90)
> > 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 distinction and this ordering don't seem to be well spelled out in the Reference Manual; thank you for explaining them. . . . > > 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 ... 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. Is the `object' really an object by the time operator delete() gets at it? An object is a region of memory with a type, and the type is stripped when the object is destroyed. All that's left by the invocation of operator delete() is a typeless region of memory. In an Aristotelian sense, it's no longer a `thing,' it's just `stuff.' I agree that the terminology would benefit from clarification. -- (This man's opinions are his own.) From mole-end Mark Terribile