If you’d like me to take a look at your code, feel free to e-mail it to me. I think I already might see where you could be confused from looking at your code, though.
includes.h:
#ifndef file1
#include “file1.h”
#ifndef file2
#include “file2.h”
//if this part is not after the files(-includes) that
use it it will produce errors
#ifndef fileimp
#include “fileimportant.h”
//
file1:
#define file1
#include “includes.h”
struct yyy{
abc here;
};
file1: // I assume you mean file2 here?
#define file2
#include “includes.h”
struct xxx{
abc hereto;
yyy file1;//this should produce an error, because file 2 is after file 1 in includes.h
};
fileimportant.h:
#define fileimp
#include “includes.h”
struct abc{
};
Now… assume that in your .cpp file you do
#include “file1.h”
That will first include “includes.h”, which will in turn include “file2.h”, which will then include “includes.h” again, wich this time will include “fileimportant.h”. SO! You now have
fileimportant.h
remainder of file2.h
remainder of file1.h
Which translates to
struct abc{
};
struct xxx{
abc hereto;
yyy file1
};
struct yyy{
abc here;
};
Which is obviously wrong.
Likewise if you #include “file2.h” first the order becomes
fileimportant.h
remainder of file1.h
remainder of file2.h
So you get
struct abc{
};
struct yyy{
abc here;
};
struct xxx{
abc hereto;
yyy file1
};
Which would be right.
Lastly if you #include “fileimportant.h” you get
file2.h
remainder of file1.h
remainder of fileimportant.h
or
struct xxx{
abc hereto;
yyy file1
};
struct yyy{
abc here;
};
struct abc{
};
Which still is not right.
As you can see, trying to do this with precompiler stuff the way you did makes things needlessly messy and didn’t even fix anything. And actually, in that example you don’t even have circular dependencies. All you probably have to do is at the top of one of your two headers pre-declare the other class.
[edit]Got confused myself while evaluating the headers and fixed them above.
[/edit]
[This message has been edited by Deiussum (edited 06-27-2001).]