Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!elroy!orion.cf.uci.edu!uci-ics!siam.ics.uci.edu!schmidt From: schmidt@siam.ics.uci.edu (Doug Schmidt) Newsgroups: comp.lang.c++ Subject: Making operators ``new'' and ``delete'' private. Keywords: new, delete Message-ID: <7581@paris.ics.uci.edu> Date: 16 Feb 89 00:03:43 GMT Sender: news@paris.ics.uci.edu Reply-To: Doug Schmidt Distribution: comp Organization: University of California at Irvine: ICS Dept. Lines: 38 Hi, I would appreciate it if a C++ language lawyer would explain whether the following program is valid C++ as defined by the most recent version of cfront (i.e., 2.0). In particular, is it possible to prevent use of ``new'' and ``delete'' outside of the context of class member scope? Also, is it valid for the ``delete'' operator to declare the ``X*'' parameter, or must it use ``void *?'' ---------------------------------------- class X { public: X (int) { ; } private: void *operator new (long sz) { printf ("hello\n"); } void operator delete (X* p) { printf ("goodbye\n"); } }; main () { X* a = new X(1); // Is this incorrect use of private new? delete a; // Is this incorrect use of private delete? } ---------------------------------------- Thanks for your help. Doug Schmidt -- schmidt@ics.uci.edu (ARPA) | Per me si va nella citta' dolente. office: (714) 856-4043 | Per me si va nell'eterno dolore. | Per me si va tra la perduta gente. | Lasciate ogni speranza o voi ch'entrate.