fork(3) download
  1. #include <memory>
  2.  
  3. class T {
  4. public:
  5. T() = default;
  6.  
  7. // Disallow moving:
  8. T(T&&) = delete;
  9. T& operator = (T&&) = delete;
  10. };
  11.  
  12. int main() {
  13. // Moving a unique_ptr works:
  14. std::unique_ptr<T> a(new T);
  15. std::unique_ptr<T> b(std::move(a));
  16.  
  17. // Moving a T does not work:
  18. T x;
  19. T y(std::move(x)); //< Compile error
  20. }
  21.  
Compilation error #stdin compilation error #stdout 0s 3424KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:19:18: error: use of deleted function ‘T::T(T&&)’
  T y(std::move(x)); //< Compile error
                  ^
prog.cpp:8:2: error: declared here
  T(T&&) = delete;
  ^
stdout
Standard output is empty