-
#include question
I want to include <string> in my main file, as well as a subfile that I included in my mainfile. However, I have noticed that if I #include it in both files, I pay for it twice in terms of EXE bulk.
My question is how does one go about having access to strings in all the associated files, but without having to include it in each, which is silly? Is there any way to send includes "down the line"?
I sort of hate to ask this, but all the C++ learning info seems to gloss over details like this, so answers are slim for this kind of question.
-
you must be seeing some other behavior because including <string> in each *.cpp file will not, in itself, cause the executable to become larger with each *.cpp file that you add to the project. You can include <string> as many times as you desire with no change in executable size.
-
Including a header doesn't effect the size of an executable at all because headers contain only declarations and they don't produce any code..
Kurt
-
make sure you are compiling your code in 'release' mode instead of 'debug' mode
-
also, normally you cant always include headers as much as you like if they dont have a "definition procedure"
like
Code:
#ifndef HEADER_H
#define HEADER_H
// header code
#endif
this is to prevent if a user adds the header twice youd get a error this means if its been included it defines HEADER_H if its been included again HEADER_H would already be defined so the whole header code would be void