fork download
  1. #include <iostream>
  2. using namespace std;
  3. class c;
  4.  
  5.  
  6. class a
  7. {
  8. public:
  9. int x;
  10. c& refC;
  11.  
  12. a(int a,c& objC):refC(objC)
  13. {
  14. x=a;
  15. std::cout<<"in a"<<x<<std::endl;
  16. }
  17. };
  18. class c
  19. {
  20. public:
  21. a& aRef;
  22. int y;
  23. c(a& ref):aRef(ref)
  24. {
  25. cout<<"in c"<<endl;
  26. y=10;
  27. }
  28. void print()
  29. {
  30. cout<<"value of y:"<<y<<endl;
  31. }
  32. };
  33. class b
  34. {
  35. public:
  36. a objA;
  37. c objC;
  38. b():objC(objA),objA(10,objC)
  39. {
  40. std::cout<<"in b"<<std::endl;
  41. }
  42. };
  43. int main() {
  44. // your code goes here
  45. b objB;
  46. return 0;
  47. }
Compilation error #stdin compilation error #stdout 0s 15232KB
stdin
Standard input is empty
compilation info
prog.cpp: In constructor ‘a::a(int, c&)’:
prog.cpp:16:7: error: invalid use of incomplete type ‘class c’
   refC.print();
       ^
prog.cpp:3:7: note: forward declaration of ‘class c’
 class c;
       ^
stdout
Standard output is empty