Header A needing Header B needing Header A.

Hi,

What is the best/tidiest way of removing the problem of "Header A" needing something from "Header B" which in turn needs something from "Header A".

Thanks,
Uni
LVL 3
Unimatrix_001Asked:
Who is Participating?
 
sunnycoderConnect With a Mentor Commented:
One way is forward declaration. If a type uses only pointers of another type, you can use a fwd declaration.
Else you can divide the contents into multiple header files ... say header C and move dependencies to it. That should break the cycle.

If you can provide details of your exact need, may be we can help better

0
 
jkrConnect With a Mentor Commented:
Usually forward declarations (see http://en.wikipedia.org/wiki/Forward_declaration). I.e.


//a.h
 
class B; // forward declaration
 
class A {
 
protected:
 
B* b;
};
 
//b.h
#include "a.h"
 
class B: {
 
protected:
 
A* a;
};

Open in new window

0
 
Unimatrix_001Author Commented:
Thanks both. :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.