🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++
Article #314

Visibility of overloaded ``new''

#314
From: "Douglas C. Schmidt"
Date: Wed, 05 Oct 1988 03:29
41 lines
1310 bytes
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 <stream.h>

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";   
}
Technical Details
Message-ID: <8810042029.aa01081@PARIS.ICS.UCI.EDU>
Path: arc1-ca.pugleaf.net!utzoo!telly!ddsw1!lll-winken!uunet!tut.cis.ohio-state.edu!ORION.CF.UCI.EDU!schmidt%crimee.ics.uci.edu

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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