Reputation: 14448
As the question states, i am a C#/Java programmer who is interested in (re)learning C++. As you know C#/Java have a somewhat strict project file structure (especially Java). I find this structure to be very helpful and was wondering if it is a) good practice to do a similar structure in a C++, b) if so, what is the best way to setup it up?
i know there is the basic 'headers' and 'source' folders, but is there a better way?
Upvotes: 3
Views: 423
Reputation: 20031
a) (is it) good practice to do a similar structure in a C++,
One way to find out would be to download a few open source projects and look at their file structure.
In my experience, the build tool used really ends up dictating the file structure. If it's a bit of a pain to have lots of subdirectories with your build tool of choice then you won't have lots of subdirectories.
b) if so, what is the best way to set it up?
That depends on your build/dev environment. I personally use vim and Linux file tools, so I set this all up by hand. Somebody using Eclipse or Visual Studio probably has a number of wizards to work from.
Upvotes: 1
Reputation: 506877
I find the structure of java projects quite nice. I do it like this (root is the root directory)
root/include/foo/bar/baz.hpp becomes
namespace foo {
namespace bar {
// declare/define the stuff (classes, functions) here
} } // foo::bar
in code.
I keep the source in
root/src/foo/bar/baz.cpp . If i have some stuff that is not exposed to the outside, i put it into a detail/ directory and namespace. I keep the makefiles at root/.
Upvotes: 3