Seriously, I can't seem to find a solid description of how the include hierarchy in C++ exactly works. And I'm just blundering around and trying this and that, but I don't really get it.
For example:
I have a common.h header that declares most of the stuff that's used by most anything else, and includes the most important library headers. First off, it includes orbitersdk.h
Now, I thought it would be a nice thing to put an include of that file first in every source file, and right after that include the header of the sourcefile. This was recommended by several people on the net, although they seem to presupose that you're having an Idea of what you're doing to begin with and don't explain how the whole thing actually works.
Now, I have my main cpp file, the one with #define ORBITER_MODULE at the start. So I go on and include common.h first, and then the header file declaring the stuff that's in the cpp file itself.
As a result, it doesn't recognise anything from orbitersdk.h.
So I change it and include only the header of the source file, and in that header first include common.h, which includes orbitersdk.h. And it works.
So
source->common.h->orbitersdk.h->return to source->source.h
does not work.
while
source->source.h->common.h->orbitersdk->return to source.h
works fine.
I don't get the logic here. What about the order is actually important? obviously it's not the same if I include a file from a cpp file or from a header file. Why is it not the same? From where exactly must a header file be included and which other header files then have access to it? I'm completely lost here. Obviously it's not just a question of order, it's also a question of where you include from.
Could someone just give me a few clues here?
For example:
I have a common.h header that declares most of the stuff that's used by most anything else, and includes the most important library headers. First off, it includes orbitersdk.h
Now, I thought it would be a nice thing to put an include of that file first in every source file, and right after that include the header of the sourcefile. This was recommended by several people on the net, although they seem to presupose that you're having an Idea of what you're doing to begin with and don't explain how the whole thing actually works.
Now, I have my main cpp file, the one with #define ORBITER_MODULE at the start. So I go on and include common.h first, and then the header file declaring the stuff that's in the cpp file itself.
As a result, it doesn't recognise anything from orbitersdk.h.
So I change it and include only the header of the source file, and in that header first include common.h, which includes orbitersdk.h. And it works.
So
source->common.h->orbitersdk.h->return to source->source.h
does not work.
while
source->source.h->common.h->orbitersdk->return to source.h
works fine.
I don't get the logic here. What about the order is actually important? obviously it's not the same if I include a file from a cpp file or from a header file. Why is it not the same? From where exactly must a header file be included and which other header files then have access to it? I'm completely lost here. Obviously it's not just a question of order, it's also a question of where you include from.
Could someone just give me a few clues here?