How to share libraries through several header files?

Hello,

I have decided to header files to help clean up my code. The thing is, that in my header files, several functions use the same library.

To my knowledge, when I compile, then if I have #include <string> in 3 of the header files, it will be loaded three times. I want to avoid this bad practice.

Could anyone recommend a solution?

Thank you.
closed account (E0p9LyTq)
To my knowledge, when I compile, then if I have #include <string> in 3 of the header files, it will be loaded three times.

Your knowledge is slightly faulty. The C++ standard library headers have inclusion guards to prevent including them more than once, same for the C standard library headers. Most 3rd party libraries have the same feature.

Each translation unit (.c/.cpp source file) requires whatever library headers it needs to be included, but multiple includes won't add them multiple times.

Yes, the header files are loaded to be read by the preprocessor, but they are not added to the source file(s) more than once. Courtesy of inclusion guards.

Last edited on
Oh I see, thank you for clarifying this.
Topic archived. No new replies allowed.