Path: utzoo!telly!ddsw1!lll-winken!uunet!tut.cis.ohio-state.edu!ORION.CF.UCI.EDU!schmidt%crimee.ics.uci.edu From: schmidt%crimee.ics.uci.edu@ORION.CF.UCI.EDU ("Douglas C. Schmidt") Newsgroups: gnu.g++ Subject: Visibility of overloaded ``new'' Message-ID: <8810042029.aa01081@PARIS.ICS.UCI.EDU> Date: 5 Oct 88 03:29:09 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 40 Hi, In the following code, the operator ``new'' has been defined in the private section of class foo. Shouldn't this make it illegal to use the keyword ``new'' outside of the context of the member functions and friends? Assignment ( = ) and ``pass-by-value'' can be disallowed by following this trick, so why not allocation as well? Doug here's an example: ---------------------------------------- #include class foo { private: int j; int k; void * operator new(long size) { cout << size << "\n"; return(malloc(size)); } public: foo(int i) { j = k = i; } int Return(void) { return(j * k); } }; main() { foo Bar(1); foo *Bard = new foo(2); cout << "Bar.Return() = " << Bar.Return() << "\n"; cout << "Bard.->Return() = " << Bard->Return() << "\n"; }