fork download
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::endl;
  5.  
  6. class B;
  7.  
  8. class A {
  9. B* b_;
  10.  
  11. public:
  12. A(B* b) : b_(b) { cout << "Конструктор А" << endl; }
  13. void func_1();
  14. void func_2() { cout << "Класс A func_2" << endl; }
  15. };
  16.  
  17. class B {
  18. A a;
  19.  
  20. public:
  21. B() : a(this) { cout << "Конструктор B" << endl; }
  22.  
  23. void func_1() {
  24. cout << "Класс В func_1" << endl;
  25. a.func_1();
  26. }
  27.  
  28. void func_2() {
  29. cout << "Класс В func_2" << endl;
  30. a.func_2();
  31. }
  32. };
  33.  
  34. void A::func_1() {
  35. cout << "Класс А func_1" << endl;
  36. b_->func_2();
  37. }
  38.  
  39. int main() {
  40. B b;
  41. b.func_1();
  42. }
  43.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
Конструктор А
Конструктор B
Класс В func_1
Класс А func_1
Класс В func_2
Класс A func_2