Topic: operator delete is static?


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 10 Dec 1994 03:53:02 GMT
Raw View
jg@cv.hp.com (Joe Gilray) writes:

>I understand why a class-specific operator new is static (whether or not
>it is explicitly declared so) - new needs be be callable when no instance
>of the class yet exists.  But why must class-specific operator delete be
>static?  It needs to be called for an instance, doesn't it?

When you write
 delete p;
where 'p' points to an object of type T, first T's destructor gets
invoked, then operator delete() is called. By the time operator
delete() is called, you no longer have a a type T object, but just
raw storage. ('Raw Bits', for PHC fans.)
--
Steve Clamage, stephen.clamage@eng.sun.com




Author: pjl@graceland.att.com (Paul J. Lucas)
Date: Sat, 10 Dec 1994 08:34:51 GMT
Raw View
In <1994Dec10.013220.10663@hpcvca.cv.hp.com> jg@cv.hp.com (Joe Gilray) writes:

>I understand why a class-specific operator new is static (whether or not
>it is explicitly declared so) - new needs be be callable when no instance
>of the class yet exists.  But why must class-specific operator delete be
>static?  It needs to be called for an instance, doesn't it?

 No; the destructor is called for an instance to turn an instance
 into raw memory; delete returns raw memory to the operating
 system; hence, delete does not operate on an object.
--
 - Paul J. Lucas
   AT&T Bell Laboratories
   Naperville, IL




Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Sun, 11 Dec 1994 04:51:23 GMT
Raw View
In article <1994Dec10.013220.10663@hpcvca.cv.hp.com> jg@cv.hp.com (Joe Gilray) writes:
>I understand why a class-specific operator new is static (whether or not
>it is explicitly declared so) - new needs be be callable when no instance
>of the class yet exists.  But why must class-specific operator delete be
>static?  It needs to be called for an instance, doesn't it?

 In reality a class operator delete acts as if it were
a virtual non-static member (provided the destructor is virtual).

 Delete is static because it does not take an instance
of the object as an argument -- only the raw memory left after
the object is gone. For the same reasons constructors are,
in effect, static.
--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,
        81A Glebe Point Rd, GLEBE   Mem: SA IT/9/22,SC22/WG21
        NSW 2037, AUSTRALIA     Phone: 61-2-566-2189




Author: jg@cv.hp.com (Joe Gilray)
Date: Sat, 10 Dec 1994 01:32:20 GMT
Raw View
I understand why a class-specific operator new is static (whether or not
it is explicitly declared so) - new needs be be callable when no instance
of the class yet exists.  But why must class-specific operator delete be
static?  It needs to be called for an instance, doesn't it?

-Joe Gilray