[comp.lang.c++] Making operators ``new'' and ``delete'' private.

schmidt@siam.ics.uci.edu (Doug Schmidt) (02/16/89)

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.