Header A needing Header B needing Header A.

Posted on 2008-06-16
Last Modified: 2010-04-21

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".

Question by:Unimatrix_001
LVL 45

Accepted Solution

sunnycoder earned 250 total points
ID: 21794986
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

LVL 86

Assisted Solution

jkr earned 250 total points
ID: 21795007
Usually forward declarations (see I.e.

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

Open in new window


Author Closing Comment

ID: 31467672
Thanks both. :)

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

828 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