Jump to content
  • Advertisement
Sign in to follow this  
MadScientist

Setting up headers and project files

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

So I'm an intermediate to advanced programmer and can program a good deal of things. But I still don't know how certain files should be used in a project to keep it organized. I know that cpp files have all the main code and headers have declarations and includes but I don't know how to arrange them. I have a main.cpp file that I use for the bulk of the code but where should I put the functions? In another .cpp file or a header file and if it is a .cpp file how do I properly include it so that the headers included in the header file can be accessed by the cpp file that isnt the main. I'm using visual c++.

Share this post


Link to post
Share on other sites
Advertisement
There's no one way to do it so you'll just have to find what works for you. What i'll do is write everything in main.cpp and when i see that several functions operate on a specific type of data, or do a specific subset of things, i'll move those functions to their own headers and sources. I do the same for classes.

For me, it's just easier to write and refactor than write it right the first time.

Share this post


Link to post
Share on other sites
You can group functions that belong together in one file, a class can go into it's own file, if there are many small classes that belong together you can put them all in one file. For each source (.cpp) file you have header file (main.cpp is probably an exception and don't need a header file).

So say that you have an item class. You can have a header named item.h that contains the class definition and a source file named item.cpp that defines the member functions. To be able to use the item class from another file you include item.h.

Share this post


Link to post
Share on other sites
No you never include .cpp files. All you need to do is make sure all .cpp files get compiled and then linked together. Exactly how to do this depends on your compiler/IDE.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!