fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //#include "B.h"
  5.  
  6. class B;
  7.  
  8. class A
  9. {
  10. B b;
  11. // or
  12. void do_something(B b) { this.b = b; }
  13. // or
  14. B getB() const { return this.b; }
  15. };
  16.  
  17.  
  18. int main() {
  19. // your code goes here
  20. return 0;
  21. }
Compilation error #stdin compilation error #stdout 0s 16064KB
stdin
Standard input is empty
compilation info
prog.cpp:10:5: error: field ‘b’ has incomplete type ‘B’
   B b;
     ^
prog.cpp:6:7: note: forward declaration of ‘class B’
 class B;
       ^
prog.cpp: In member function ‘void A::do_something(B)’:
prog.cpp:12:23: error: ‘b’ has incomplete type
   void do_something(B b) { this.b = b; }
                       ^
prog.cpp:6:7: note: forward declaration of ‘class B’
 class B;
       ^
prog.cpp:12:33: error: request for member ‘b’ in ‘(A*)this’, which is of pointer type ‘A*’ (maybe you meant to use ‘->’ ?)
   void do_something(B b) { this.b = b; }
                                 ^
prog.cpp: In member function ‘B A::getB() const’:
prog.cpp:14:18: error: return type ‘class B’ is incomplete
   B getB() const { return this.b; }
                  ^
prog.cpp:14:32: error: request for member ‘b’ in ‘(const A*)this’, which is of pointer type ‘const A*’ (maybe you meant to use ‘->’ ?)
   B getB() const { return this.b; }
                                ^
stdout
Standard output is empty