Search code examples
c++projecthierarchy

Project files' tree


Are there any articles or recommendations how to organize file hierarchy in your project? I am interested in how to name folders, to separate sources and headers or not.

I have project written in C++, a library and project using it. Library has many components, they are separated from each other but some of them use common files. Should I create directories for them?

I will be glad to hear all recommendations.


Solution

  • It's good to keep your namespaces in separate folders. Nest namespaces in the same manner as they are nested within your project. For instance, if you have:

    namespace Foo{ namespace Bar{ } }
    

    then you'd want any objects in the Bar namespace to be found in

    {Foo's parent folder}\Foo\Bar\{how you're organizing code at this level}

    We use an include folder for headers, a source for .cpp, a test folder for unit tests, and an object folder for compiled code bits. The reason we separate them is that it makes it easier to package the code in our scripts. You're always going to pass around the headers, you won't be passing around the source. (Here is another SO thread discussing separating header/source files. It's a preference thing.)

    Here is a link to Google's style guidelines, if that helps.