fork(1) download
  1. #include <memory>
  2. #include <iostream>
  3.  
  4.  
  5. class SomeClass {
  6. public:
  7. SomeClass() {
  8. std::cout << "SomeClass()" << std::endl;
  9. }
  10.  
  11. ~SomeClass() {
  12. std::cout << "~SomeClass()" << std::endl;
  13. }
  14.  
  15. void* operator new(std::size_t size) {
  16. std::cout << "Custom new" << std::endl;
  17. return ::operator new(size);
  18. }
  19.  
  20. void operator delete(void* ptr, std::size_t size) {
  21. std::cout << "Custom delete" << std::endl;
  22. ::operator delete(ptr);
  23. }
  24. };
  25.  
  26.  
  27.  
  28. int main() {
  29. std::shared_ptr<SomeClass> ptr1(new SomeClass);
  30. std::cout << std::endl << "Another one..." << std::endl << std::endl;
  31. std::shared_ptr<SomeClass> ptr2(std::make_shared<SomeClass>());
  32. std::cout << std::endl << "Done!" << std::endl << std::endl;
  33. }
  34.  
Success #stdin #stdout 0s 3064KB
stdin
Standard input is empty
stdout
Custom new
SomeClass()

Another one...

SomeClass()

Done!

~SomeClass()
~SomeClass()
Custom delete