fork(1) download
  1. #include <iostream>
  2. #include <memory>
  3. #include <cstdint>
  4.  
  5. using namespace std;
  6.  
  7. template< typename T >
  8. struct array_deleter
  9. {
  10. void operator ()( T const * p)
  11. {
  12. cout << "using delete[]" << endl;
  13. delete[] p;
  14. }
  15. };
  16.  
  17. int8_t* allocate_func()
  18. {
  19. cout << "allocating array" << endl;
  20. return new int8_t[10];
  21. }
  22.  
  23. int main() {
  24. int8_t *ptr = allocate_func();
  25. cout << "creating smart pointer" << endl;
  26. shared_ptr<int8_t> sptr(ptr, array_deleter<int8_t>());
  27. cout << "exiting main" << endl;
  28. return 0;
  29. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
allocating array
creating smart pointer
exiting main
using delete[]