I’ve got a personal project, which I doubt would exceed 20 pairs of header/cpp files. I was wondering whether it would be better to have each header and cpp file include the other files that it needs (or use forward declarations), or have every file include “Includes.hpp” which in turn includes all of the standard libraries, gives a forward declaration for each class, then includes all of my other headers.
As I can see, using one big header file:
- Cleans everything up
- Makes it easier to include these files from other directories (as you only need to navigate to use one file, which then links all of the others)
- Will include all files for every compilation, which considering this is a small project, isn’t a disadvantage, as I’ll be using all of the files
Is this a good idea?
I would say that in general this is a bad idea for several reasons:
#undef MINwill know this pain.I think though there is one instance where it may be acceptable, which is if your library only provides a few classes/functions that are intended to be called by clients, and all the rest are just internal classes used by the implementation. So clients can just include
mylib.hand that’s all they need to worry about. This also makes it easier if you want to compile your library as a static library as you can just distribute the library and one header.