-
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.
-
use directives to check on what has been declared:
Code:
#ifndef MYCLASS1
#define MYCLASS1
..... do your thing here
#endif
-
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.