fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct A;
  6. struct B;
  7.  
  8. struct A
  9. {
  10. inline void f();
  11.  
  12. B* b;
  13. int val;
  14. };
  15.  
  16. struct B
  17. {
  18. inline void f();
  19. A* a;
  20. int val;
  21. };
  22.  
  23. void A::f()
  24. {
  25. cout << b->a->val << endl;
  26. }
  27.  
  28. void B::f()
  29. {
  30. cout << a->b->val << endl;
  31. }
  32.  
  33. int main()
  34. {
  35. A a;
  36. B b;
  37. a.val = 10;
  38. b.val = 20;
  39. a.b = &b;
  40. b.a = &a;
  41.  
  42. a.f();
  43. b.f();
  44. }
  45.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
10
20