Path: utzoo!attcan!uunet!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!udel!burdvax!ubbpc!wgh From: wgh@ubbpc.UUCP (William G. Hutchison) Newsgroups: comp.lang.c++ Subject: Why redefine operator new if you do not have to? Keywords: operator new allocation constructor novice Message-ID: <749@ubbpc.UUCP> Date: 17 Sep 90 22:22:39 GMT Distribution: na Organization: Unisys UNIX Portation Center, Blue Bell, PA Lines: 44 We have a problem here in the Philadelphia area. No, I do not mean that Philadelphia's municipal bonds have a rating of 'B' :-{ The president of a local software firm has taken it upon himself to make public lectures about C++. He bought Turbo C++ a few weeks ago and he has not yet finished reading the Annotated C++ Reference Manual (!!). This gent is an accomplished C programmer, and I do not want to embarrass him more than necessary, so I will refer to him as 'Joe' (not his name). Joe has been using an 'infinite precision' integer package as an example in his talks. He has presented a C version, and he is now discussing how to implement the package as a C class called Number. He is doing OK except on the subject of constructors. Joe has some weird concept that a constructor should do type conversion, like Number(int), but that a different technique is needed for storage allocation, as in "allocate a 10-digit Number". Joe thinks that a cool way to do storage allocation for Number is to define his own Number::operator new(). I explained that new() was already set up for class Number, and he does not have to redefine it, and that redefining new() is for replacing the allocation mechanism, and that Number(int x=0) is a good constructor and that it is never necessary to allocate an empty Number in advance (the storage can be allocated as needed). But Joe just doesn't get it. How can I explain this to a beginner who thinks he is an expert in C++ because he knows C real well and he has read half a book on C++? By the way, Joe has never heard of libg++ and he thinks that GNU software is low quality hacker stuff. His ego will not allow him to accept that the GNU folks write better code than he ever did. I plan to print out your responses to this query and distribute them at the next session of the computer association next month. Thank you for your support! -- Bill Hutchison, DP Consultant rutgers!cbmvax!burdvax!ubbpc!wgh (work) Unisys UNIX Portation Center uunet!eidolon!wgh (home) P.O. Box 500, M.S. B121 "At the moment I feel more like arguing than Blue Bell, PA 19424 being good" Raymond Smullyan _The Tao is Silent_