Jump to content
  • Advertisement
Sign in to follow this  
Betrayer_of_Code

WHY do you split files?

This topic is 5462 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 understand that in many larger programs you would have to split the source into different source files (.cpp, .h). But what do you put in each. Do you only put specific data in .h's or .cpp's and what is the realtionship between two .cpp's in the same file? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Organization and maintainability is the primary reason.
A header, and its corresponding code files would have related items of code in them. For instance, a header might declare an object, but the .cpp would actually define the methods. This way when you need to change the object, you don't go digging through one huge file, but instead a couple of small headers and source files.

It also means that when compiling, and linking, you can use partial rebuilds. Thus reducing the amount of time spent compiling and linking the application due to changes.

Share this post


Link to post
Share on other sites
Source code is split into many different files for many reasons. As a simple example, you could have graphics.h and .cpp, audio.h and .cpp and game.h and .cpp. Then later you could reuse audio and graphics and write a new game without having to create new engines.

Quote:
what is the realtionship between two .cpp's in the same file?


I'm not really sure what you mean by this because two cpp's will be in two different files...

Share this post


Link to post
Share on other sites
I usually put function declarations and class declarations. In the header files remember to add the #ifndef, #define, and #endif. So it doesn't get included more then once. In the .cpp files i put the actual funcion code. Then it will all get linked together. If you want to use the functions just delcare the .h file. It is really hard to get used to how everything is linked together, but in the end, it is very kool.

If you have any problems, PM me. I have manage with help from this forum, and other resources on the net, to figure most of it all out.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!