Is there some way to #include standard things locally (for one function, one class, etc... at a time) instead of globally. Taking a very simple example one might want to use std::string but it is only needed in one class and you don't want the overhead of it existing everywhere.
Instead of making #include
local, you should probably just move the class that requires it into a separate file.
Since #include
is simply just a kind of text replacement before compilation (by the preprocessor), it is just a matter of where you put the include statement.
Likely, you are refering to "locally" as "in just one .cpp file" and to "globally" as "in all .cpp files".
If this is true, you can make an #include
as "locally" by only including in that .cpp files where you want it. If you want to include a file with one #include
statement in several files, place the include statement into a .h file and include that .h file inside all required files.
A good place to make a "global" #include
is the .h header file that serves as the precompiled header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With