fork download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. struct S {
  5. std::string a;
  6. int b;
  7.  
  8. S(const S&) = default;
  9. S(S&&) = default;
  10. S& operator=(const S&) = default;
  11. S& operator=(S&&) = default; // not required here but should be added for completeness
  12.  
  13. ~S() {
  14. std::cout << a << " " << b << std::endl;
  15. }
  16. };
  17.  
  18. S f(S arg) {
  19. S s0{};
  20. S s1(s0); //s1 {s0}; in the book
  21. s1 = arg;
  22. return s1;
  23. }
  24.  
  25. int main()
  26. {
  27. S s3{"tool",42};
  28. f(s3);
  29. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
 0
tool 42
tool 42
tool 42