fork download
  1. #include <new>
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <stdexcept>
  5.  
  6. struct foo {};
  7.  
  8. inline void* operator new(size_t size, foo*) throw (std::bad_alloc)
  9. {
  10. std::cout << "my new " << size << std::endl;
  11. return malloc(size);
  12. }
  13.  
  14. inline void operator delete(void* p, foo*) throw()
  15. {
  16. std::cout << "my delete" << std::endl;
  17. free(p);
  18. }
  19.  
  20. int main()
  21. {
  22. delete new((foo*)NULL) foo;
  23. }
Success #stdin #stdout 0.01s 2856KB
stdin
Standard input is empty
stdout
my new 1