This is the first time I've tackled a c++ program with more than 10 files included in it, and I'm having a hard time understanding how to order the files which get included.
I'm guessing there's a method to this madness but it's still basically a crapshoot. One thing I discovered is that the headers which tend to be used in every other header should be pushed to the bottom when being included in the source cpp file which includes main().
And then there are the orders I don't understand.
Let's say there's a header that's called by every other header but does not include anything itself. I'll call this "A.h". Then there's "B.h" and "C.h" which includes "A.h".
Finally, this gets included in "main.cpp". (btw, they all have include guards). The top of "main.cpp" would look like this:
Code:
#include <standard c++ headers>
#include ...
#include "B.h"
#include "C.h"
#include "A.h"
If I move "A.h" above "B.h", then I get some stupid error like this:
Code:
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\assert.h(59): error C2059: syntax error : 'constant'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\assert.h(181): error C2018: unknown character '0x3'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\assert.h(189): fatal error C1071: unexpected end of file found in comment
Finally, I'm trying to use the greta regular expression library. It works okay but only if I place it at the very top of the include list. I don't get it. WTF does include order have to do with how it compiles? This works but the others just give me internal compiler errors:
Code:
// This order works
#include "greta/regexpr2.h"
#include <standard c++ headers>
#include ...
#include "B.h"
#include "C.h"
#include "A.h"
// This order doesn't
#include <standard c++ headers>
#include ...
#include "greta/regexpr2.h"
#include "B.h"
#include "C.h"
#include "A.h"
// Neither does this
#include <standard c++ headers>
#include ...
#include "B.h"
#include "C.h"
#include "A.h"
#include "greta/regexpr2.h"
Could somebody tell me what's going on? Or if you could point me to some coherent tutorial, that would be most helpful.