I am having some difficulties with cyclic dependency between two classes. Situation is something like following -
Expand|Select|Wrap|Line Numbers
- ///A.h
- #include "B.h"
- class A {
- {
- int X;
- public:
- P() { Q(); }
- Q() {
- R();
- bb = new B();
- bb.D( this ); )
- R() { uses X )
- };
- ///B.h
- class B: public someclass {
- public:
- D(A& a) {
- a.Q(); //end condition for recursion depends on X
- a.R();
- };
I couldn't create D() in A as D() access private data in B. But D() calls
both Q() and R() and value of X has to be same everywhere. i.e. R()
called from D access the same X value that was used by class A. That's why I am passing this pointer of class A to B. There will be just one instance of A and B. But there isn't just one class B, there are lots of classes like B derived from a parent class. I am actually creating objects for these classes, kind of linked list. A has functions for creating a list, but it may be nested that's why there is a recursion.
PROBLEM-
Forward declaration of A in B doesn't work and I can't include header of A to B as header of B is included in A. I am using kdevelop on suse.
How do I solve this thing? Sorry for such a long description.
Any help would be very appreciated. Thanks.