Jump to content
  • Advertisement
Sign in to follow this  
Extrakun

How to you organise your cpp and header files?

This topic is 3320 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 am working on a new project and trying to come up with ways to organise my cpp and header files. I am using VS 2005, breaking up different functionality of the project into different smaller projects inside the solution. I was originally thinking of 1) have the .h file together with the .cpp OR 2) have a folder called src, and another called include, and have a parallel structure that looks like this: \src\Data \src\Modules . . . \include\Data \include\Modules I am not writing a library (but some of the functionalities may be reused by other projects later)...which approach is better for the long run? Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
After a couple of years I decided (at least for now) that the best way to organize my source files is .h and .cpp in the same folder, and the directory structure organized exactly as the namespaces defined in the program/library (A contains B contains C).

Share this post


Link to post
Share on other sites
I tend to just dump all source files in a single directory, and let IntelliSense deal with it. I used to do the whole nested-directories thing, but I don't find it worth the effort to maintain these days - at least for C++: languages with a proper package mechanism (such as Python) are another story.

Share this post


Link to post
Share on other sites
I tend to do the same thing as owl: group .cpp and .h files together and mirroring the namespace structure. Intellisense often breaks on templated code, so dumping everything into one directory doesn't work very well for me.

Share this post


Link to post
Share on other sites
include/src with parallel directory structures for now. This is mostly to cater to my own sense of structure: when #include-ing files, I'd rather see something like #include "resources/cache/resource_cache.h" than simply #include "resource_cache.h". This way I can get a sense of which systems depend on which other systems just by looking at the directories from which they pull their #includes.

Share this post


Link to post
Share on other sites
I keep a...
* include folder for shared headers(without extension) & template implementations
* a source folder for non-shared headers(with extension) and source folders
Both have sub-directories roughly based around project/namespaces (the enum hack comes to mind as an exception)

Share this post


Link to post
Share on other sites
I toss everything in one folder and use filters in Visual Studio to organize them within the IDE.

Share this post


Link to post
Share on other sites
Quote:
Original post by owl
After a couple of years I decided (at least for now) that the best way to organize my source files is .h and .cpp in the same folder, and the directory structure organized exactly as the namespaces defined in the program/library (A contains B contains C).


Exactly, its what I use as well...almost by default I done it that way for the first time. If you give a class a category (namespace) it makes very much sense to put it in the same category directory wise.

Share this post


Link to post
Share on other sites
I have found over the years that there are very strong advantages to mimicing the C++ namespace heirarchy with a source file namespace heirarchy. This eliminates filename conflicts the same way it does variable and type names.

I have also found the urge to place headers and sources in separate directory heirarchies somewhat weird and unjustifiable. Sources and headers go together. When generating a dev package for a library the headers get pulled and packaged separately anyways.

Generally, assets are kept in a separate directory heirarchy because they are run-time data not build-time data.

Packaging metadata is also stored separately from sources. This simplifies making targeted source distributions.

Finally, a separate heirarchy for test suites are separate from sources. Testing should be orthogonal to building and packaging.

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!