home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / C / ANSICPP.ZIP / EX03006.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-24  |  563 b   |  30 lines

  1. // ex03006.cpp
  2. // Home-brew new and delete
  3. #include <iostream.h>
  4. #include <stdlib.h>
  5. #include <stddef.h>
  6.  
  7. // ------------- overloaded new operator
  8. static void *operator new(size_t size)
  9. {
  10.     void *rtn = calloc(1, size);
  11.     return rtn;
  12. }
  13.  
  14. // ----------- overloaded delete operator
  15. static void operator delete(void *type)
  16. {
  17.     free(type);
  18. }
  19.  
  20. main()
  21. {
  22.     // ------ allocate a zero-filled array
  23.     int *ip = new int[10];
  24.     // ------ display the array
  25.     for (int i = 0; i < 10; i++)
  26.         cout << " " << ip[i];
  27.     // ----- release the memory
  28.     delete ip;
  29. }
  30.