Connecting classes with pointers

I want two classes to hold a pointer to each other.

C++Builder stops my compile with "files nested too deep" when I try this:

File: test.cpp
#include "a.h"
#include "b.h"

int main(){A a; B b; a.link(&b); b.link(&a); return 0;}

File: a.h
#pragma hdrstop
#include "b.h"
#ifndef A_H
#define A_H
Class A {
  public:
     link(B* b_addr){b_ptr = b_addr;}
  private:
    B* b_ptr;
}
#endif

File: b.h
#pragma hdrstop
#include "a.h"
#ifndef B_H
#define B_H
Class B {
  public:
     link(A* a_addr){a_ptr = a_addr;}
  private:
    A* a_ptr;
}
#endif

I don't want to have to create a superclass over these classes (and thus each class would hold a reference to this superclass and use polymorphic calls.) How can I avoid the recursive header file loading?
}
shadow66Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

shadow66Author Commented:
Edited text of question.
0
chensuCommented:
Replace

#include "b.h"

with

class B;  // forward declaration


Replace

#include "a.h"

with

class A;  // forward declaration
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rdfCommented:
include your a.h in your b.h and then you only need to #include your b.h in your main

or if you have a b.cpp, # include a.h and b.h in b.cpp and #include b.cpp in your main

0
shadow66Author Commented:
Thanks for the quick response (for so few points...). I'm trying to learn C++ on my own--through books, CDs, etc. Any book recommendations?

Thanks again.
0
chensuCommented:
Sorry, I haven't read a C++ study book for a long time. I have been reading some references and documentation.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.