Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!netcomsv!sjsumcs!horstman From: horstman@mathcs.sjsu.edu (Cay Horstmann) Newsgroups: comp.lang.c++ Subject: Re: proposal for new/delete extension Message-ID: <1991Jun27.124812.4991@mathcs.sjsu.edu> Date: 27 Jun 91 12:48:12 GMT References: <19215@prometheus.megatest.UUCP> Organization: San Jose State University - Math/CS Dept. Lines: 30 In article <19215@prometheus.megatest.UUCP> djones@megatest.UUCP (Dave Jones) writes: > >I recommend an alternate way to specify class-specific operators new >and delete which stipulates that they must not be inherited: > >class Class1 { > char goodies[SIZE]; > public: > Class1 *operator new(); > void operator delete(Class1*); >}; > >Notice that this version of operator new does not take a size_t parameter. Let me split this up into two points. (1) I think that defining operator new() instead of operator new(size_t) as a fixed-size allocator that cannot be inherited is a reasonable idea. (PLEASE don't ask to inherit it in only those classes that don't add any data.) (2) I think the question whether that operator new, or any operator new, should return a Class* rather than a void*, is an independent question. Even in the normal case, with inherited operator new, it makes sense to return a Class*. Why DOES operator new return a void* in C++? The standard argument is that the constructor has to first run on the allocated block of memory to turn the bits into an object. If you want to push your idea of a size-specific, non-inheritable operator new, I think you should just stick to void* Class::operator new(). Cay