Confused about including headers

Sep 26, 2014 at 7:54am
So I am using an external library and including its header, let's say <library.h>

My project has a number of helper functions in different cpp files, each one has a header that includes that <library.h>.

My main cpp file needs to use the library and the other helper functions. So its header includes all the helper headers and the <library.h>.

Is this how it's supposed to be? Or is the <library.h> actually included/compiled A LOT of times?
Sep 26, 2014 at 8:10am
That is why you have header guards. It prevents inclusion more than once. So in the end only first ectountered include of particular header will work.
Sep 26, 2014 at 8:14am
I have header guards on the headers for the helper functions, but still, each one includes <library.h> as it needs to use it. Not sure how to change the structure
Last edited on Sep 26, 2014 at 8:14am
Sep 26, 2014 at 8:18am
If library has the proper guard too, you are fine. Else you need to hope that it does not contain anything which lead to errors wit multiple inclusions. Other than that you do not need to worry.
Sep 26, 2014 at 8:22am
good point, i checked the library header and it has a #pragma once so it should be alright
Topic archived. No new replies allowed.