pointers - How can I do that? Classes call functions from each others (include-forward anomaly) -


i call foo() function class through other class's pointer (i cannot include other class's header, cause on other class, result ,,contains itself'' error)

//a.h   class x; // here can't include "x.h", forward declaration, results incomplete type  class {  x* ptr;   void example()  {   x->foo();    // can't use, casue ,,incomplete type not allowed''  }    void print(); } 

//x.h #include "a.h"  class x {  a* ptrarray[];   void foo();   void list()  {   (i...)     ptrarray[i]->print();  // ok, works fine  } } 

how can around problem, can give me advice?

define foo() , void list() in file. , pass x , first parameter them. when define them there not error of incomplete type, because compiler have got definition early. thrid file like

// wrapper.h include <a.h> include <x.h>  void foo(x *objx, ....); void list(a *obja, ....);  //wrapper.cpp void foo(x *objx, ....) {   objx->foo(....);   }  void list(a *obja, ....) {   obja->list()l } 

Comments