fork download
  1. #include <iostream>
  2. #include <boost/optional.hpp>
  3.  
  4. struct X
  5. {
  6. int x;
  7. boost::optional<X&> parent;
  8. };
  9.  
  10. int main()
  11. {
  12. X a, b;
  13. a.x = 1; b.x = 2;
  14. b.parent = a;
  15. std::cout << b.parent->x << "\n";
  16.  
  17. a.x = 42;
  18. std::cout << b.parent->x << "\n";
  19. }
  20.  
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
1
42