fork(1) download
  1. #include <utility>
  2.  
  3. template <typename T>
  4. struct Foo
  5. {
  6. T t;
  7. Foo(const T& t) : t(t) { }
  8. Foo(T&& t) : t(std::move(t)) { }
  9. };
  10.  
  11. struct Bar
  12. {
  13. Bar() { }
  14. Bar(int) { }
  15. Bar(const Bar&) = default;
  16. Bar(Bar&&) = delete;
  17. };
  18.  
  19. int main() {
  20. Foo<Bar> foobar1(Bar()); //compiles fine
  21. Foo<Bar> foobar2(Bar(5)); //error: use of deleted function 'Bar::Bar(Bar&&)
  22.  
  23. return 0;
  24. }
Compilation error #stdin compilation error #stdout 0s 3136KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'Foo<T>::Foo(T&&) [with T = Bar]':
prog.cpp:21:25:   required from here
prog.cpp:8:29: error: use of deleted function 'Bar::Bar(Bar&&)'
  Foo(T&& t) : t(std::move(t)) { }
                             ^
prog.cpp:16:2: note: declared here
  Bar(Bar&&) = delete;
  ^
stdout
Standard output is empty