• Advertisement

Archived

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

simple #include design opinion

This topic is 5909 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

Is it a bad design to include headers within headers? ... or I should say, is it better to not include headers within headers? I thought I overheard someone say this one time ... and I figured it''s so that you''d see up front (in your source files) what all the dependencies are. thanks.

Share this post


Link to post
Share on other sites
Advertisement
It can speed up compile times _if you can just use forward references.

The defacto advice is to let the user include any standard headers that are required, but you should be sure to include the neccessary headers that you''ve written that are needed for it to compile.

Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

"What I see is a system that _could do anything - but currently does nothing !" - Anonymous CEO

Share this post


Link to post
Share on other sites
I certainly argee. Don''t make the user memorize a list of includes that he has to include before he includes your header. Even just the run-time library would be a real nightmare if the headers for each didn''t include all the others it needs. You shouldn''t get carried away. Generally one source one header. That means you write one header file for one source file, not that you only include one. The main exception is where you want to hide the implementation of a library from the user. So one header exposes all the classes/functions that you intend for them to use and another has the additional classes/function you need to actually implement it.

Share this post


Link to post
Share on other sites

  • Advertisement