Search code examples
include

Does every code in header file A get included in header file B assuming those header files are in the same file


So lets say im in some file that has two header files A and B. I want to know if the stuff inside A.h gets included in B.h. In otherwords if A.h had a public function called getFoo() then would B.h be able to know what getFoo() is because its being included from A.h?

#include "A.h"
#include "B.h"

Solution

  • I want to know if the stuff inside A.h gets included in B.h

    No, it doesn’t (unless you have #include "A.h" inside B.h but you seem to imply that you don’t).

    However, remember that inclusion is literally just textual substitution. This means that, whatever file you’ve shown in your question, includes both A.h and B.h. Therefore, in this translation unit declarations in A.h precede those in B.h and can therefore be used by code in B.h.