fork download
  1. #include <iostream>
  2.  
  3. #include <cstdlib>
  4. #include <new>
  5.  
  6. void* operator new(std::size_t size, const char* file, int line)
  7. {
  8. std::clog << file << ": " << line << std::endl;
  9. void * t_pNewHeapObject = std::malloc( size );
  10.  
  11. if ( t_pNewHeapObject )
  12. {
  13. // Meine implementierung
  14. return t_pNewHeapObject;
  15. }
  16. throw std::bad_alloc{};
  17. }
  18. //----------------------------------------------------------------------------
  19. void* operator new [](std::size_t size, const char* file, int line)
  20. {
  21. void * t_pNewHeapObject = std::malloc( size );
  22.  
  23. if ( t_pNewHeapObject )
  24. {
  25. // Meine implementierung
  26. return t_pNewHeapObject;
  27. }
  28. throw std::bad_alloc{};
  29. }
  30. //----------------------------------------------------------------------------
  31. void operator delete(void* ptr) noexcept
  32. {
  33. // Meine implementierung
  34. std::free(ptr);
  35. ptr= nullptr;
  36. }
  37. //----------------------------------------------------------------------------
  38. #define new new(__FILE__, __LINE__)
  39. //----------------------------------------------------------------------------
  40.  
  41. //using namespace std;
  42.  
  43. int main() {
  44. int* p = new int;
  45.  
  46. delete p;
  47. return 0;
  48. }
  49.  
Success #stdin #stdout #stderr 0.01s 5400KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.cpp: 44