-
Circular includes
Hi, I have a simple problem, most likely faced by someone before.
I have 3 classes Cell, Juxtacrine and Morphogen. Juxtacrine is derived from Cell, and Morphogen is derived from Cell also.
Basically the two derived classes both include the Cell.h to find the definition of Cell.
The problem comes when i need to use the Objects in the main function eg
Code:
#include "Juxtacrine.h"
#include "Morphogen.h"
int main()
{
Juxtacrine j;
Morphogen m;
return 0;
}
This obviously causes the circular include, and was wondering if there is a way to use preprocessor directives to stop this happening eg
Code:
#ifndef CELL_H
#include "Cell.h"
#endif
But this doesnt seem to fix it. Has anyone got an idea how to get around this? I dont really want to have to work out what class includes what as ill have several classes with multiple inheritence later on, which will cause a headache working out the circular includes if i do it manually...
Heres my code if u need it...
Code:
class Cell
{
public:
Cell();
~Cell();
private:
virtual void signal();
};
Code:
#include "Cell.h"
class Juxtacrine : public Cell
{
public:
Juxtacrine();
~Juxtacrine();
private :
void signal();
};
Code:
#include "Cell.h"
class Morphogen : public Cell
{
public:
Morphogen();
~Morphogen();
private :
void signal();
};
Im Using WinXP / VC++ (if needed)
-
Code:
#ifndef CELL_H
#include "Cell.h"
#endif
should be
Code:
#ifndef CELL_H
#define CELL_H
#include "Cell.h"
#endif
But this would go in the header itself. so the source code would be:
Code:
#include "Cell.h"
#include <blah blah blah>
and inside of the header you would have
Code:
#ifndef CELL_H
#define CELL_H
// All your definations and such
#endif
-
Excellent, thats fixed it ! Thanks!