home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c031 / 4.ddi / SAMPLES / CPPTUTOR / NEWDEL.CP$ / NEWDEL
Encoding:
Text File  |  1991-12-12  |  666 b   |  32 lines

  1. // NEWDEL.CPP
  2.  
  3. // This is an example program from Chapter 6 of the C++ Tutorial. This
  4. //    program demonstrates customized new and delete operators.
  5.  
  6. #include <iostream.h>
  7. #include <malloc.h>
  8.  
  9. // ------------- Overloaded new operator
  10. void *operator new( size_t size )
  11. {
  12.     void *rtn = calloc( 1, size );
  13.     return rtn;
  14. }
  15.  
  16. // ----------- Overloaded delete operator
  17. void operator delete( void *ptr )
  18. {
  19.     free( ptr );
  20. }
  21.  
  22. void main()
  23. {
  24.     // Allocate a zero-filled array
  25.     int *ip = new int[10];
  26.     // Display the array
  27.     for( int i = 0; i < 10; i++ )
  28.         cout << " " << ip[i];
  29.     // Release the memory
  30.     delete [] ip;
  31. }
  32.