|
-
Mar 19th, 2002, 01:18 AM
#1
Thread Starter
Lively Member
recursive #include calls
I have two classes that are codependant. They both have functions that call instances of the other class.
Each class is defined in its own header file. Say Class1.h and Class2.h
Right now I have #include "Class2.h" in my Class1.h file and #include "Class1.h" in my Class2.h file.
Naturally when I compile its falls into a small recursive loop before returning a C2061: syntax error.
each header file has code such that it only compiles once.
I'm using VC 6.0 is there a simple way to solve this problem short of using a lib solution?
Thanks in advance.
-
Mar 19th, 2002, 09:59 AM
#2
use directives to check on what has been declared:
Code:
#ifndef MYCLASS1
#define MYCLASS1
..... do your thing here
#endif
-
Mar 19th, 2002, 11:40 AM
#3
Put the real code of the classes in a .cpp file and leave only the declarations in the header. Then add forward declarations before both classes:
class A;
class B
{
A* pA;
};
In the cpp files you simply include both headers.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|