My question concerns the topic of organizing C ++ sources. Below are two ways: the usual and alternative. I use the second method in my "hobby" projects. I want to hear the opinion of the experienced whether to use it or not, and why?
- Habitual
The set of source codes is divided into two sets: header files and files with implementations. That is, all the familiar *.hpp and *.cpp , *.cc files. The implementation files "include" header files. Each implementation file results in *.obj , which are later used by the linker to get the executable file.
When using this method, very often the header file is located next to the implementation file. Examples: SuperFactory.hpp and next to it lies in the same folder SuperFactory.cpp
- Alternative
This method differs from the above in that instead of a large number of implementation files, a single implementation file, implementation.cpp, is created. Yes, one cpp-file. You can do this as follows: *.cpp , *.cc files become header files containing implementations and included in implementation.cpp .
In this method, header files containing ads are in a separate folder, for example include . And the header files contain the implementation in another implementation . Schematically can be represented as:
include\ ...proba1.hpp ...proba2.hpp implementation\ ...proba1.hpp ...proba2.hpp include.hpp: #include <include/proba1.hpp> #include <include/proba2.hpp> implementation.hpp: #include <implementation/proba1.hpp> #include <implementation/proba2.hpp> implementation.cpp: #include <precompiled_headers.hpp> #include <include.hpp> #include <implementation.hpp> As mentioned above, I use the second method in my "hobby" projects. I want to understand what can be the reason for not using the second method, and why?