Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 11th, 2012  |  syntax: None  |  size: 0.80 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. operator new with empty exception-specification calling constructor when allocation returns 0
  2. void * operator new (size_t s, PersistentMemory * m) throw()
  3.    {return m->allocatePersistentMemory(s);}
  4.        
  5. void *myalloc (size_t) { return 0; }
  6. void * operator new (size_t s) throw() { return myalloc(s); }
  7. struct Foo {
  8.     std::string s;
  9.     Foo () { std::cout << this << std::endl; }
  10. };
  11. int main () {
  12.     Foo *f = new Foo;
  13.     if (f == 0) std::cout << "f is NULL" << std::endl;
  14. }
  15.        
  16. void *myalloc (size_t) { return 0; }
  17. void * operator new (size_t s) throw() { return myalloc(s); }
  18. struct Foo {
  19.     std::string s;
  20.     Foo () { std::cout << this << std::endl; }
  21.     void * operator new (size_t s) { return myalloc(s); }
  22. };
  23. int main () {
  24.     Foo *f = new Foo;
  25.     if (f == 0) std::cout << "f is NULL" << std::endl;
  26. }