Skip to main content
gamedev.net
🔒 Locked

C++ nested includes

Started by dcosborn Nov 28, 2003 at 12:59 AM 0 replies 450+ views
Original Post
dcosborn
dcosborn
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
Wavarian
Wavarian
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.