fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A;
  5. class B;
  6.  
  7. class A
  8. {
  9. public:
  10. A(B& b, int v);
  11.  
  12. B& m_b;
  13. int m_value;
  14. };
  15.  
  16. class B
  17. {
  18. public:
  19. B(A& a, int v);
  20.  
  21. A& m_a;
  22. int m_value;
  23. };
  24.  
  25. A::A(B& b, int v) : m_b(b), m_value(v) { }
  26. B::B(A& a, int v) : m_a(a) ,m_value(v) { }
  27.  
  28.  
  29. class C
  30. {
  31. public:
  32. C() : a(b, 2), b(a, 5) {
  33. cout << a.m_value;
  34. cout << b.m_value;
  35. cout << a.m_b.m_value;
  36. cout << b.m_a.m_value;
  37. }
  38.  
  39. A a;
  40. B b;
  41. };
  42.  
  43.  
  44. int main() {
  45. C c;
  46. return 0;
  47. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
2552