fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <memory>
  4. #include <new>
  5.  
  6. struct X
  7. {
  8. void *
  9. operator new(
  10. std::size_t count )
  11. {
  12. std::cout << "Custom new called." << std::endl;
  13. return std::malloc( count );
  14. }
  15.  
  16. void
  17. operator delete(
  18. void * addr )
  19. {
  20. std::cout << "Custom delete called." << std::endl;
  21. return std::free( addr );
  22. }
  23. };
  24.  
  25. int
  26. main( int, char ** )
  27. {
  28. std::cout << "std::make_shared" << std::endl;
  29. {
  30. std::make_shared<X>();
  31. }
  32. std::cout << "no std::make_shared" << std::endl;
  33. {
  34. std::shared_ptr<X>( new X() );
  35. }
  36. return 0;
  37. }
  38.  
  39.  
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
std::make_shared
no std::make_shared
Custom new called.
Custom delete called.