I think the general procedure for a circular dependence is to write a forward declaration (if Wikipedia is to be trusted). This seems to work unless the class requiring the forward declaration has other classes which are inherited from it.
Up until this point I haven't had any forays into circular dependence, so when I tried it out I was getting a lot of errors "base class undefined". I found that I could get it to compile again by either (1) removing the circular dependence, or (2) moving the circular dependence to the leaf classes. Unfortunately, if I have to move the dependence to the leaf class, then what is the point of having this parent class when the shared code can't be shared?
So I created a test project just to test if the circular dependence in a parent class was the problem or if it was some forward declaration that I had missed. The result is that either I did the same thing wrong twice or this just can't be done. I had the same problem in my test project as in my original project.
So am I correct? Or did I do the same thing wrong twice?
Well, I guess if I did the same thing wrong twice, I better post my test project so someone can identify the problem (just the headers):
Parent Class:
#ifndef HEADER_PUREABSTRACT
//#if !defined HEADER_PUREABSTRACT
#define HEADER_PUREABSTRACT
#include "Derived1.h"
class CDerived1;
class CPureAbstract
{
public:
virtual int ImaVirtualFunction(void); //=0;
protected:
CPureAbstract(void);
~CPureAbstract(void);
};
#endif
Derived1.h
#ifndef HEADER_DERIVED1
//#if !defined HEADER_DERIVED1
#define HEADER_DERIVED1
#include "PureAbstract.h"
class CDerived1 : public CPureAbstract
{
public:
int ImaVirtualFunction(void);
CDerived1(void);
~CDerived1(void);
};
#endif
Derived2.h
#ifndef HEADER_DERIVED2
//#if !defined HEADER_DERIVED2
#define HEADER_DERIVED2
#include "PureAbstract.h"
class CDerived2 : public CPureAbstract
{
public:
int ImaVirtualFunction(void);
CDerived2(void);
~CDerived2(void);
};
#endif
In my original project, the circular dependence is more of a pointer to a container class. The CActor class has a pointer to the CActorContainer class (well, I would like for it to).