[gnu.g++] Visibility of overloaded ``new''

schmidt%crimee.ics.uci.edu@ORION.CF.UCI.EDU ("Douglas C. Schmidt") (10/05/88)

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";   
}