0

I wrote two classes with these dependencies.

//a.h
class B: 
class A{
 B *b ;
 A() { b = new B(this);}
 print();
}



  // b.h
    class A;
    class B{
     A* a;
     B(A *_a){ this->a = _a }
     void foo() { a->print(); } // here i have error : use of undefined type a
   }

If I comment 'a->print()' the code compiles and the other function works, but when I use the pointer of class A in class B, I'm getting this error:

"use of undefined type a"

Can anyone solve my problem?

Thanks

man-qa
  • 377
  • 6
  • 26
mostafa88
  • 532
  • 1
  • 8
  • 20

1 Answers1

2

You need to move the implementation of the methods outside the header and inside implementation files.

To do a->print(); or new B(this), a full definition is required.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625