fork(1) download
  1. #include <iostream>
  2.  
  3. struct CopyOnly
  4. {
  5. CopyOnly() = default;
  6. CopyOnly(const CopyOnly&) = default;
  7. CopyOnly(CopyOnly&&) = delete;
  8. };
  9.  
  10. struct Verbose
  11. {
  12. Verbose() { std::cout << "default constructor" << std::endl; }
  13. Verbose(const Verbose&) { std::cout << "copy constructor" << std::endl; }
  14. Verbose(Verbose&&) { std::cout << "move constructor" << std::endl; }
  15. };
  16.  
  17. struct A : CopyOnly, Verbose {};
  18.  
  19. void foo(A &&x){ std::cout<<"&&" <<std::endl; A a(std::move(x));}
  20.  
  21. void foo(A &x){ std::cout<<"&" <<std::endl; A a(x);}
  22.  
  23. int main() {
  24. foo(A()); // prints &&
  25. A a;
  26. foo(a); // prints &
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
default constructor
&&
copy constructor
default constructor
&
copy constructor