-2

For example, as in Java, we can manage the code something like this:

come.xxx.ui
           .dialogs
           .custome_views
           ...
           .MainFrame
        .domain
           .Product
           ...
        .exceptions
           .UserNotFoundException
           ...
        .utils
           ...

In this way, it is all clear that which code belongs to which part, on a very large project. But how we can do something like this in C++ to keep the project clean, in a small project it may be no problem, but on a large project, it will be hard to have control on code and classes in one directory.

kometen
  • 6,536
  • 6
  • 41
  • 51
Bahramdun Adil
  • 5,907
  • 7
  • 35
  • 68
  • 1
    Create as many directories as you want, and use correct paths in `#include`s – CinCout May 19 '17 at 10:04
  • 1
    Which directory you put your code in has nothing to do with the language. You can use namespaces in C++ all you want with the `namespace` keyword. This is covered in any book on the C++ language. However, do note that while deep hierarchies may be idiomatic Java, they are *not* idiomatic C++. Namespaces are primarily used to prevent namespace collisions, not for "packaging" purposes. – Cody Gray - on strike May 19 '17 at 10:04
  • Follow the principle of least surprise: http://stackoverflow.com/a/5006955/412080 – Maxim Egorushkin May 19 '17 at 10:06
  • Related: http://stackoverflow.com/questions/713698/c-namespaces-advice, http://stackoverflow.com/questions/4240984/src-folder-structure-in-c, and http://stackoverflow.com/questions/4792823/java-packages-vs-c-libraries – Cody Gray - on strike May 19 '17 at 10:10

1 Answers1

2

Ordering of files in project by directories and namespaces is independent in C++.

You can order files by directories how do you want, just create subprojects (if you want separate libs and executable files) in your building system or just specify building directories for one big project.

And you can move some parts of code to namespaces how do you want, just write

namespace NamespaceName
{
...
}

around of your code in each source and header files. And namespaces could be nested.

Of course, it is better if your splitting to namespaces and subprojects will be related.

knst
  • 523
  • 2
  • 16