How does #include work in C++?

No, #includes are transitive.

However, if your second file itself uses symbols from someLibrary, it’s good style to re-include the header. That way you’re not “hoping and praying” that you never remove the intermediate include. Your codebase will be more robust if every source file #includes everything that it directly needs. Header guards prevent this from being a wasteful policy.

Leave a Comment