fork(1) download
  1. #include <iostream>
  2. #include <utility>
  3. struct A;
  4. struct B
  5. {
  6. A& ref;
  7. int n;
  8. void show() const;
  9. };
  10.  
  11. struct A
  12. {
  13. B& ref;
  14. int n;
  15. void show() const;
  16. };
  17.  
  18. void A::show() const
  19. {
  20. std::cout << "A.n is " << n
  21. << " A.ref.n is " << ref.n
  22. << " A.ref.ref.n is " << ref.ref.n
  23. << " A.ref.ref.ref.n is " << ref.ref.ref.n
  24. << '\n';
  25. }
  26.  
  27. void B::show() const
  28. {
  29. std::cout << "B.n is " << n
  30. << " B.ref.n is " << ref.n
  31. << " B.ref.ref.n is " << ref.ref.n
  32. << " B.ref.ref.ref.n is " << ref.ref.ref.n
  33. << '\n';
  34. }
  35.  
  36. int main()
  37. {
  38. struct {A first; B second;} pair = {{pair.second, 2}, {pair.first, 1}};
  39. pair.first.show();
  40. pair.second.show();
  41. }
  42.  
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
A.n is 2 A.ref.n is 1 A.ref.ref.n is 2 A.ref.ref.ref.n is 1
B.n is 1 B.ref.n is 2 B.ref.ref.n is 1 B.ref.ref.ref.n is 2