Listing 21 Replaces global operator new and operator delete

// override.cpp
#include <iostream.h>
#include <stdlib.h>

void *operator new(size_t siz)
{
   cout << "allocating " << siz << " bytes" << endl;
   return malloc(siz);
}
void operator delete(void *p)
{
   cout << "deleting memory at " << (void *)p << endl;
   free(p);
}

main()
{
   double *dp = new double;
   delete dp;
   return 0;
}

/* Output:
allocating 8 bytes
deleting memory at 0x19e0
*/
// End of File