fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class b;
  5.  
  6. class a {
  7. private:
  8. int num1 = 10, num2 = 20;
  9.  
  10. public:
  11. friend class b;
  12. void print(b &obj);
  13. };
  14.  
  15. class b {
  16. private:
  17. int c = 9;
  18.  
  19. public:
  20. friend class a;
  21. void print(a &obj) {
  22. cout << obj.num1 << " " << obj.num2 << endl;
  23. }
  24. };
  25.  
  26.  
  27. void a::print(b &obj) {
  28. cout << obj.c << endl;
  29. }
  30.  
  31. int main() {
  32. a obj1;
  33. b obj2;
  34. obj1.print(obj2);
  35. obj2.print(obj1);
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
9
10 20