Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

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
0
Unimatrix_001
Asked:
Unimatrix_001
2 Solutions
 
sunnycoderCommented:
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
 
jkrCommented:
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now