Guest User

Untitled

a guest
Aug 11th, 2012
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment