fork download
  1. #include <iostream>
  2.  
  3. struct A {
  4. //A & operator = ( A & ) { return *this; }
  5. A & operator = ( A & ) = default;
  6. };
  7.  
  8. int & foo( int n ) {
  9. std::cout << n << ' ';
  10. static int x;
  11. return x;
  12. }
  13.  
  14. A & bar( int n ) {
  15. std::cout << n << ' ';
  16. static A a;
  17. return a;
  18. }
  19.  
  20. int main() {
  21. foo( 1 ) = foo( 2 ) = foo( 3 ); // 1, 2, 3
  22. std::cout << std::endl;
  23. bar( 1 ) = bar( 2 ) = bar( 3 ); // 3, 2, 1
  24. std::cout << std::endl;
  25. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
1 2 3 
1 2 3