fork(1) download
  1. #include <memory>
  2.  
  3. class Base
  4. {
  5. };
  6.  
  7. class Derived : public Base
  8. {
  9. };
  10.  
  11. struct BaseDeleter
  12. {
  13. void operator()(Base* base)
  14. {
  15. // Perform some special deleting
  16. }
  17. };
  18.  
  19. class Big
  20. {
  21. public:
  22. Big()
  23. {
  24. //pointer.reset(new Derived()); // This works!
  25. pointer = std::make_unique<Derived, BaseDeleter>(); // But this doesn't...
  26. }
  27.  
  28. private:
  29. std::unique_ptr<Base, BaseDeleter> pointer;
  30. };
  31.  
  32. int main()
  33. {
  34. Big clazz;
  35. }
Compilation error #stdin compilation error #stdout 0s 3456KB
stdin
Standard input is empty
compilation info
prog.cpp: In constructor 'Big::Big()':
prog.cpp:25:52: error: no matching function for call to 'make_unique()'
   pointer = std::make_unique<Derived, BaseDeleter>(); // But this doesn't...
                                                    ^
In file included from /usr/include/c++/5/memory:81:0,
                 from prog.cpp:1:
/usr/include/c++/5/bits/unique_ptr.h:764:5: note: candidate: typename std::_MakeUniq<_Tp>::__single_object std::make_unique(_Args&& ...) [with _Tp = Derived; _Args = {BaseDeleter}; typename std::_MakeUniq<_Tp>::__single_object = std::unique_ptr<Derived, std::default_delete<Derived> >]
     make_unique(_Args&&... __args)
     ^
/usr/include/c++/5/bits/unique_ptr.h:764:5: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/5/bits/unique_ptr.h:770:5: note: candidate: template<class _Tp> typename std::_MakeUniq<_Tp>::__array std::make_unique(std::size_t)
     make_unique(size_t __num)
     ^
/usr/include/c++/5/bits/unique_ptr.h:770:5: note:   template argument deduction/substitution failed:
prog.cpp:25:52: error: wrong number of template arguments (2, should be 1)
   pointer = std::make_unique<Derived, BaseDeleter>(); // But this doesn't...
                                                    ^
In file included from /usr/include/c++/5/memory:81:0,
                 from prog.cpp:1:
/usr/include/c++/5/bits/unique_ptr.h:776:5: note: candidate: template<class _Tp, class ... _Args> typename std::_MakeUniq<_Tp>::__invalid_type std::make_unique(_Args&& ...) <deleted>
     make_unique(_Args&&...) = delete;
     ^
/usr/include/c++/5/bits/unique_ptr.h:776:5: note:   template argument deduction/substitution failed:
/usr/include/c++/5/bits/unique_ptr.h: In substitution of 'template<class _Tp, class ... _Args> typename std::_MakeUniq<_Tp>::__invalid_type std::make_unique(_Args&& ...) [with _Tp = Derived; _Args = {BaseDeleter}]':
prog.cpp:25:52:   required from here
/usr/include/c++/5/bits/unique_ptr.h:776:5: error: no type named '__invalid_type' in 'struct std::_MakeUniq<Derived>'
stdout
Standard output is empty