fork download
  1. #include <iostream>
  2. #include <memory>
  3. using namespace std;
  4.  
  5. class asd
  6. {
  7. public:
  8. asd(int a) : c(a) {}
  9. int c;
  10. };
  11.  
  12. int main() {
  13. // your code goes here
  14. std::unique_ptr<asd*> a(new asd(2));
  15. std::cout << a->c;
  16. }
Compilation error #stdin compilation error #stdout 0s 16064KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:14:36: error: no matching function for call to ‘std::unique_ptr<asd*>::unique_ptr(asd*)’
  std::unique_ptr<asd*> a(new asd(2));
                                    ^
In file included from /usr/include/c++/6/memory:81:0,
                 from prog.cpp:2:
/usr/include/c++/6/bits/unique_ptr.h:231:2: note: candidate: template<class _Up, class> std::unique_ptr<_Tp, _Dp>::unique_ptr(std::auto_ptr<_Up>&&)
  unique_ptr(auto_ptr<_Up>&& __u) noexcept;
  ^~~~~~~~~~
/usr/include/c++/6/bits/unique_ptr.h:231:2: note:   template argument deduction/substitution failed:
prog.cpp:14:36: note:   mismatched types ‘std::auto_ptr<_Up>’ and ‘asd*’
  std::unique_ptr<asd*> a(new asd(2));
                                    ^
In file included from /usr/include/c++/6/memory:81:0,
                 from prog.cpp:2:
/usr/include/c++/6/bits/unique_ptr.h:223:2: note: candidate: template<class _Up, class _Ep, class> std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Up, _Ep>&&)
  unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
  ^~~~~~~~~~
/usr/include/c++/6/bits/unique_ptr.h:223:2: note:   template argument deduction/substitution failed:
prog.cpp:14:36: note:   mismatched types ‘std::unique_ptr<_Tp, _Dp>’ and ‘asd*’
  std::unique_ptr<asd*> a(new asd(2));
                                    ^
In file included from /usr/include/c++/6/memory:81:0,
                 from prog.cpp:2:
/usr/include/c++/6/bits/unique_ptr.h:209:7: note: candidate: std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Tp, _Dp>&&) [with _Tp = asd*; _Dp = std::default_delete<asd*>]
       unique_ptr(unique_ptr&& __u) noexcept
       ^~~~~~~~~~
/usr/include/c++/6/bits/unique_ptr.h:209:7: note:   no known conversion for argument 1 from ‘asd*’ to ‘std::unique_ptr<asd*>&&’
/usr/include/c++/6/bits/unique_ptr.h:204:17: note: candidate: constexpr std::unique_ptr<_Tp, _Dp>::unique_ptr(std::nullptr_t) [with _Tp = asd*; _Dp = std::default_delete<asd*>; std::nullptr_t = std::nullptr_t]
       constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { }
                 ^~~~~~~~~~
/usr/include/c++/6/bits/unique_ptr.h:204:17: note:   no known conversion for argument 1 from ‘asd*’ to ‘std::nullptr_t’
/usr/include/c++/6/bits/unique_ptr.h:197:7: note: candidate: std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Tp, _Dp>::pointer, typename std::remove_reference<_To>::type&&) [with _Tp = asd*; _Dp = std::default_delete<asd*>; std::unique_ptr<_Tp, _Dp>::pointer = asd**; typename std::remove_reference<_To>::type = std::default_delete<asd*>]
       unique_ptr(pointer __p,
       ^~~~~~~~~~
/usr/include/c++/6/bits/unique_ptr.h:197:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/6/bits/unique_ptr.h:185:7: note: candidate: std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Tp, _Dp>::pointer, typename std::conditional<std::is_reference<_Dp>::value, _Dp, const _Dp&>::type) [with _Tp = asd*; _Dp = std::default_delete<asd*>; std::unique_ptr<_Tp, _Dp>::pointer = asd**; typename std::conditional<std::is_reference<_Dp>::value, _Dp, const _Dp&>::type = const std::default_delete<asd*>&]
       unique_ptr(pointer __p,
       ^~~~~~~~~~
/usr/include/c++/6/bits/unique_ptr.h:185:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/6/bits/unique_ptr.h:170:7: note: candidate: std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Tp, _Dp>::pointer) [with _Tp = asd*; _Dp = std::default_delete<asd*>; std::unique_ptr<_Tp, _Dp>::pointer = asd**]
       unique_ptr(pointer __p) noexcept
       ^~~~~~~~~~
/usr/include/c++/6/bits/unique_ptr.h:170:7: note:   no known conversion for argument 1 from ‘asd*’ to ‘std::unique_ptr<asd*>::pointer {aka asd**}’
/usr/include/c++/6/bits/unique_ptr.h:158:17: note: candidate: constexpr std::unique_ptr<_Tp, _Dp>::unique_ptr() [with _Tp = asd*; _Dp = std::default_delete<asd*>]
       constexpr unique_ptr() noexcept
                 ^~~~~~~~~~
/usr/include/c++/6/bits/unique_ptr.h:158:17: note:   candidate expects 0 arguments, 1 provided
prog.cpp:15:18: error: request for member ‘c’ in ‘* a.std::unique_ptr<_Tp, _Dp>::operator-><asd*, std::default_delete<asd*> >()’, which is of pointer type ‘asd*’ (maybe you meant to use ‘->’ ?)
  std::cout << a->c;
                  ^
stdout
Standard output is empty