fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. template<typename T>
  5. struct Animal {
  6. Animal() { std::cout << "Animal" << std::endl; }
  7. ~Animal() { std::cout << "~Animal" << std::endl;}
  8. };
  9.  
  10. struct Cat {
  11. Cat() { std::cout << "Cat" << std::endl; }
  12. ~Cat() { std::cout << "~Cat" << std::endl; }
  13. };
  14.  
  15. int main() {
  16. std::unique_ptr<Animal<Cat>, void(*)(Animal<Cat>*)> ptr;
  17. ptr = std::unique_ptr<Animal<Cat>, void(*)(Animal<Cat>*)>(new Animal<Cat>, [](Animal<Cat> *ls) {
  18. delete ls;
  19. });
  20. /*
  21. std::unique_ptr<Animal<Cat>, void(*)(Animal<Cat>*)> ptr(new Animal<Cat>, [](Animal<Cat> *ls) {
  22. delete ls;
  23. });
  24. */
  25. return 0;
  26. }
  27.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/c++/4.7/memory:86:0,
                 from prog.cpp:2:
/usr/include/c++/4.7/bits/unique_ptr.h: In instantiation of ‘constexpr std::unique_ptr<_Tp, _Dp>::unique_ptr() [with _Tp = Animal<Cat>; _Dp = void (*)(Animal<Cat>*)]’:
prog.cpp:16:54:   required from here
/usr/include/c++/4.7/bits/unique_ptr.h:116:9: error: static assertion failed: constructed with null function pointer deleter
stdout
Standard output is empty