Link to home
Start Free TrialLog in
Avatar of sunjian061197
sunjian061197

asked on

header file confusion

Hi,

  I want to create two classes, say class A and class B. For each class, I have a header file(A.h and B.h) as well as implementation file(A.cpp and B.cpp).  My class A has a member variable which is of the type class B. Also, in my class B, there is a member variable of type class A. i.e. the class definition looks like this:

class A {
B testMember;
...
};

class B {
A testMember;
...
};

I have "include A.h" in the B.h file and also, I "include B.h" in the A.h file. Initially i got error saying some kind of recursion definition too deep. I realized this error and added #ifdef and #endif to my program to avoid the recursion. But then I got some error saying missing decl-specifiers. I wonder what is the proper way of doing this? I am using MSVC 5.0.

Any help is appreciated!

sunjian
ASKER CERTIFIED SOLUTION
Avatar of yonat
yonat

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sunjian061197
sunjian061197

ASKER

Hi yonat,

   Thank you very much for your answer! You really saved me a lot of frustration...

sunjian