Jump to content
  • Advertisement

Archived

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

Burning_Ice

Question about #includes

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

Hi Ok, the thing is this: I have many .cpp and .h files and i had an idea how to avoid writing a dozen #includes in every .cpp file: I have a ''main include'' .h file in which i only write the #include for every other .h file, and then i only include this main include file in all .cpp files. All header files have a #pragma once and everything compiles fine Now my question is, if this way i do it has any major disadvantages i don''t know, perhaps a big memory overload or something like that. I couldn''t find anything about it in the help files, but i hope someone knows ;-) Thanks for your time, Burning_Ice

Share this post


Link to post
Share on other sites
Advertisement
Actually that''s perfectly acceptable to do - Microsoft do it themselves, in a way, with their windows.h, and stdafx.h includes. They include all the common code that every other source file in the project needs.

So you''re fine doing things like that.


#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**

Share this post


Link to post
Share on other sites
Your compile times might be slower since you are most likely often including definitions in CPP files that are not needed. You also run a greater risk of name collisions (although if it compiles ok, you''re fine here). The main thing that would annoy me in this setup though, is that changing 1 line in any 1 header file would cause the whole project to have to be rebuilt. Every single CPP file. That, for me, is the single overriding reason to not include everything at once.

Share this post


Link to post
Share on other sites
It would also make reuseability a pain in the butt. Suppose you wrote a sprite class or something that you''d like to use again in your next project - but all it''s definition stuff is glommed together with absolutely everything else from your last project. So you''re going to have to separate it out anyways, so why not do that from the beginning?

aig

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you do it like Microsoft does, you won''t have any problems. What I mean by this is put all of the things that don''t change in a header file (windows, mfc, directX, whatever other library, stuff you always use and know works, etc.) and use #pragma once and #pragma headerstop (or whatever it is) so that it doesn''t recompile everytime.
Then have each cpp file include that header and maybe a couple others, depending on what you need.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!