onilink_

Untitled

Mar 25th, 2020
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.28 KB | None | 0 0
  1.  
  2. using X = int;
  3. X x;
  4. std::function<void(void)> foo;
  5. {
  6.     X& ref = x;
  7.     foo = [&ref](){ ref = 123; };
  8. }
  9. foo();
  10.  
  11.  
  12. using X = int;
  13. std::unique_ptr<X> x = std::make_unique<X>(0);
  14. std::function<void(void)> foo;
  15. {
  16.     X& ref = *x;
  17.     foo = [&ref](){ ref = 123; };
  18. }
  19. foo();
Advertisement
Add Comment
Please, Sign In to add comment