Sign in to follow this  
MTclip

question? why not #include .. everything )

Recommended Posts

Im sure that it is not recommended but why not just put all your header delarations in one header then just include that header in all your source files for the project.... well assuming you have the proper #pragma once // #ifdef ---- what side effects could this cause.. other than reusability perhaps

Share this post


Link to post
Share on other sites
It would make it incredibly easy to make all of your program components interdepend on each other. I don't want my SoundManager to know about my Renderer etc.
Now, if a start a new game, I can just pick up my sound code from the previous game and plug it in..

Share this post


Link to post
Share on other sites
Each time you change that one header file you'll need to recompile the whole program. For small programs, you woudn't be able to tell a difference. Once programs become larger however, it becomes much more of a problem. Also, it would be a problem if the program is being written by more than one programmer. There are more problems that would probably arise, but these are probably the most prominent. A modular approach is the way to go.

Share this post


Link to post
Share on other sites
One positive aspect of that though is if you're building a library. Then a single "master" header can be quite handy for the people using your library.

Share this post


Link to post
Share on other sites
Quote:
Original post by abdulla
One positive aspect of that though is if you're building a library. Then a single "master" header can be quite handy for the people using your library.


One external header that exposes your library, perhaps. But for any significant library, there will be many more files internally.

There are two reasons not to do this:
1) As interdependencies between components grow, it can be quite difficult to make the project work. Sometimes, you'll find that a single include file simply can't resolve all of the interdependencies.
2) Compile time. Once you're working with tens of thousands of lines of code (reasonable for a serious hobby project), you do not want to be waiting for the entire thing to recompile because you made an obscure change in one part of the code.

Share this post


Link to post
Share on other sites
Usually you dont change your header file often, if so, compile times dont grow, as only neded cpp file is compiled/linked.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this