fork download
  1. #include <iostream>
  2.  
  3.  
  4.  
  5. struct Test
  6. {
  7. int & getAttr() { return x ; }
  8. int x ;
  9. } ;
  10.  
  11.  
  12.  
  13. int main()
  14. {
  15. Test t ;
  16. t.x = 10 ;
  17. int & x_ref = t.getAttr() ;
  18.  
  19. auto fn = [ & , t = std::move(t) ]
  20. {
  21. x_ref = 15 ;
  22. std::cout << "value: " << x_ref << " address:" << &x_ref << std::endl ;
  23. std::cout << "value: " << t.x << " address:" << &t.x << std::endl ;
  24. } ;
  25. fn() ;
  26. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
value: 15 address:0xbfc87424
value: 10 address:0xbfc87428