fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. int main () {
  5. std::default_delete<int> d;
  6. std::unique_ptr<int> u1;
  7. std::unique_ptr<int> u2 (nullptr);
  8. std::unique_ptr<int> u3 (new int);
  9. std::unique_ptr<int> u4 (new int, d);
  10. std::unique_ptr<int> u5 (new int, std::default_delete<int>());
  11. std::unique_ptr<int> u6 (std::move(u5));
  12. std::unique_ptr<void> u7 (std::move(u6));
  13. std::unique_ptr<int> u8 (std::auto_ptr<int>(new int));
  14.  
  15. std::cout << "u1: " << (u1?"not null":"null") << '\n';
  16. std::cout << "u2: " << (u2?"not null":"null") << '\n';
  17. std::cout << "u3: " << (u3?"not null":"null") << '\n';
  18. std::cout << "u4: " << (u4?"not null":"null") << '\n';
  19. std::cout << "u5: " << (u5?"not null":"null") << '\n';
  20. std::cout << "u6: " << (u6?"not null":"null") << '\n';
  21. std::cout << "u7: " << (u7?"not null":"null") << '\n';
  22. std::cout << "u8: " << (u8?"not null":"null") << '\n';
  23.  
  24. return 0;
  25. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/c++/4.9/memory:81:0,
                 from prog.cpp:2:
/usr/include/c++/4.9/bits/unique_ptr.h: In instantiation of 'void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = void]':
/usr/include/c++/4.9/bits/unique_ptr.h:236:16:   required from 'std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = void; _Dp = std::default_delete<void>]'
prog.cpp:12:42:   required from here
/usr/include/c++/4.9/bits/unique_ptr.h:72:2: error: static assertion failed: can't delete pointer to incomplete type
  static_assert(!is_void<_Tp>::value,
  ^
stdout
Standard output is empty