Path: utzoo!attcan!uunet!ncrlnk!ncr-sd!hp-sdd!ucsdhub!ucsd!orion.cf.uci.edu!paris.ics.uci.edu!blanche.ics.uci.edu!schmidt From: schmidt@blanche.ics.uci.edu (Doug Schmidt) Newsgroups: comp.lang.c++ Subject: overloading new operator in C++ Message-ID: <774@paris.ics.uci.edu> Date: 9 Oct 88 05:49:59 GMT Sender: news@paris.ics.uci.edu Reply-To: Doug Schmidt Organization: University of California, Irvine - Dept of ICS Lines: 37 Hi, Would someone please inform me whether the following code is legal in C++? If it is, then is the result defined? G++ 1.27 performs 20 NOPS for the main for loop. My basic question is: ``Is is possible to hide the new operator in the same fashion as hiding the assignment operator `=' , i.e., making it a compile-time error to use new?'' ---------------------------------------- #include class Tree_Node { public: static Tree_Node *Base; private: void * operator new ( long ) { return ( Base++ ); } }; main() { Tree_Node::Base = new Tree_Node [ 20 ]; for ( int i = 0; i < 20; i++ ) { cout << int ( new Tree_Node ) << "\n"; } } ---------------------------------------- thanks for any hints, Doug Schmidt