If I include a file in main that includes iostream. Will main contain iostream?
If you mean like:
Then yes.
//Main.cpp#include "SomeHeaderThatIncludesSomeOtherHeader.h"void main(void){//bla}//SomeHeaderThatIncludesSomeOtherHeader.h#include <Iostream>
Then yes.
So if I do like this:
Main (contains) "Game.h" (which contains) "SDLManager.h" (which contains) "Globals.h" (which contains) "Includer.h" (which contains) <iostream>, <SDL/SDL.h> and <string>.
That would work?
Phew, that was a long list of includes [grin]
Main (contains) "Game.h" (which contains) "SDLManager.h" (which contains) "Globals.h" (which contains) "Includer.h" (which contains) <iostream>, <SDL/SDL.h> and <string>.
That would work?
Phew, that was a long list of includes [grin]
Quote:Original post by Samsonite
So if I do like this:
Main (contains) "Game.h" (which contains) "SDLManager.h" (which contains) "Globals.h" (which contains) "Includer.h" (which contains) <iostream>, <SDL/SDL.h> and <string>.
That would work?
Phew, that was a long list of includes [grin]
If I understand that list correctly, then yes, you will have access to whatever the Game Header File includes...
Yes, that would work.
The preprocessor goes through the code, and whenever it finds an #include <file> it's as if it copies and pastes the code in that header into the spot where it finds the #include. It doesnt matter how many includes you have, because it all effectively goes into one big file by the end.
With gcc there are options so that you can see the compiler output on just running the preprocessor, without doing any further processing. If your unsure about exactly how preprocessor directives work, its worth taking a glance.
The preprocessor goes through the code, and whenever it finds an #include <file> it's as if it copies and pastes the code in that header into the spot where it finds the #include. It doesnt matter how many includes you have, because it all effectively goes into one big file by the end.
With gcc there are options so that you can see the compiler output on just running the preprocessor, without doing any further processing. If your unsure about exactly how preprocessor directives work, its worth taking a glance.
Quote:Original post by Samsonite
So if I do like this:
Main (contains) "Game.h" (which contains) "SDLManager.h" (which contains) "Globals.h" (which contains) "Includer.h" (which contains) <iostream>, <SDL/SDL.h> and <string>.
That would work?
Phew, that was a long list of includes [grin]
Yes. Which is why you should avoid unneccessary includes within headers. It creates unneccessary dependancies. Eventually, you end up in a situation where changing even a single header results in your entire project needing to be recompiled even though only one file really cares about the change. You should also not assume other files include things. If main requires std::string, then main.cpp should include <string>. If it gets included twice, oh well, that's what include guards are for. But if you end up removing <string> from some other header, you don't want to break main.cpp.
CM
If I recall, leaving such a long path of includes to get what you want might not be the best option. Altering some part on that path can lead to problems that might not be easy to figure out very quickly. Someone can correct me if I'm wrong.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement