#include #include #include #include "obj.h" using namespace std; void my_new_handler(); const char *progname; //uninitialized variable int main(int argc, char **argv) { progname = argv[0]; set_new_handler(my_new_handler); obj *const p1 = new obj(10); //Call the one-argument constructor. cout << "*p1 == " << *p1 << "\n"; cout << "The hidden numbers are " //unofficial << reinterpret_cast(p1)[-2] << " and " << reinterpret_cast(p1)[-1] << ".\n"; delete p1; cout << "\n"; int *const p2 = new int(10); //Pretend that int has constructor. cout << "*p2 == " << *p2 << "\n"; delete p2; cout << "\n"; obj *const p3 = new obj; //Call the default constructor. cout << "*p3 == " << *p3 << "\n"; delete p3; return EXIT_SUCCESS; } void my_new_handler() { cerr << progname << ": out of store\n"; exit(EXIT_FAILURE); }