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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

729 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