fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class S {
  5. public:
  6. int i;
  7. double d;
  8. S(S &&o) noexcept : i(o.i), d(o.d) {
  9. cout << "move!\n";
  10. }
  11.  
  12. S(const S &o) : i(o.i), d(o.d) {
  13. cout << "copy!\n";
  14. }
  15.  
  16. S operator=(const S &o) {
  17. i = o.i;
  18. d = o.d;
  19. cout << "copy asignment!\n";
  20. return *this;
  21. }
  22.  
  23. S operator=(S &&o) {
  24. i = o.i;
  25. d = o.d;
  26. cout << "move asignment!\n";
  27. return *this;
  28. }
  29.  
  30. S() {
  31. i = 1;
  32. d = -1;
  33. cout << "ctor!\n";
  34. }
  35.  
  36. // S fun() {
  37. // return *this;
  38. // }
  39. };
  40.  
  41. S fun() {
  42. cout << "fun!\n";
  43. S a;
  44. a.i = 100;
  45. a.d = -100;
  46. return a;
  47. }
  48.  
  49.  
  50. int main() {
  51. auto b = fun();
  52. cout << b.i << ' ' << b.d << endl;
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5516KB
stdin
Standard input is empty
stdout
fun!
ctor!
100 -100