fork download
  1. #include <iostream>
  2. #include <utility>
  3.  
  4. struct X
  5. {
  6. int n_;
  7.  
  8. explicit X(int n) : n_(n) { std::cout << "Construct: " << n_ << "\n"; }
  9. X(X const & rhs) : n_(rhs.n_) { std::cout << "X copy:" << n_ << "\n"; }
  10. X(X && rhs) : n_(rhs.n_) { rhs.n_ = -1; std::cout << "X move:" << n_ << "\n"; }
  11. ~X() { std::cout << "Destroy: " << n_ << "\n"; }
  12. };
  13.  
  14. struct A
  15. {
  16. explicit A(X x) : x_(std::move(x)) {};
  17. X x_;
  18. };
  19.  
  20. struct B
  21. {
  22. X x;
  23. };
  24.  
  25. int main()
  26. {
  27. A a(X(12));
  28. B b { X(24) };
  29. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Construct: 12
X move:12
Destroy: -1
Construct: 24
Destroy: 24
Destroy: 12