fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Example {
  5. public:
  6. int val;
  7. Example(int val) {
  8. this->val = val;
  9. }
  10. };
  11.  
  12. void swap(Example & a, Example & b) {
  13. auto temp = a;
  14. a = b;
  15. b = temp;
  16. }
  17.  
  18. int main() {
  19. auto a = Example(1);
  20. auto b = Example(2);
  21.  
  22. swap(a, b);
  23.  
  24. cout << a.val << " " << b.val;
  25. return 0;
  26. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
2 1