1#include <stdio.h> 2#include <stdlib.h> 3#include <new> 4 5int pass = 0; 6 7void * 8operator new (size_t sz, const std::nothrow_t&) throw () 9{ 10 void *p; 11 pass++; 12 p = malloc(sz); 13 return p; 14} 15 16void * 17operator new (size_t sz) throw (std::bad_alloc) 18{ 19 void *p; 20 pass++; 21 p = malloc(sz); 22 return p; 23} 24 25void 26operator delete (void *ptr) throw () 27{ 28 pass++; 29 if (ptr) 30 free (ptr); 31} 32 33class A 34{ 35public: 36 A() {} 37 ~A() { } 38 int a; 39 int b; 40}; 41 42 43int 44main (void) 45{ 46 A *bb = new A[10]; 47 delete [] bb; 48 bb = new (std::nothrow) A [10]; 49 delete [] bb; 50 51 if (pass == 4) 52 { 53 printf ("PASS\n"); 54 return 0; 55 } 56 else 57 { 58 printf ("FAIL\n"); 59 return 1; 60 } 61} 62