Solved

Header A needing Header B needing Header A.

Posted on 2008-06-16
3
143 Views
Last Modified: 2010-04-21
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
Comment
Question by:Unimatrix_001
3 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 250 total points
Comment Utility
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
 
LVL 86

Assisted Solution

by:jkr
jkr earned 250 total points
Comment Utility
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
 
LVL 3

Author Closing Comment

by:Unimatrix_001
Comment Utility
Thanks both. :)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now