Archived

This topic is now archived and is closed to further replies.

C++ nested includes

This topic is 5127 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve got a number of header files that include other headers. If a source file requires one of these headers along with a header which the aforementioned header includes for itself, should I bother explicitly including that second header in the source file? Thus far I''ve always assumed no. But what if the first header was changed and no longer included the second header? The source file would still need it and would have to be changed as well. I''m starting to think this is bad because it increases maintainance work and makes dependencies more intricate. Any thoughts? -Dave

Share this post


Link to post
Share on other sites
You''re thinking right. To prevent errors due to changes made to header files in the future, you should include all headers directly needed by the source file, and not depend on the includes of the other header files.

Just pretend that you don''t know what the other header files include, and just include what you know the source file needs.

Share this post


Link to post
Share on other sites