C++ – Combining source files, like header files

c

I have a project where my files have gotten out of hand because of the volume of them. I have started to combine classes of similar types in single header files because you can, and it still is good practice, now can i do the them same for those classes functions, that are declared in the source files.

Is it a good idea to combine several classes functions in a single source file, if the classes are say all sub classes of the same super class?

Best Answer

It is not bad practice to do so, just make sure that if the user only want a part of the system, he can include only one header and get the necessary bits. Having several definitions of class and other things in one header is fine and can even help compilation time if well done. If not well done, it can kill the build time in a bad way. So, just make sure each header gather elements that cannot be separated and that represent one (sub)module.

Look at readable C++ standard library implementation (most are not, depends on the provider) and/or better, look at boost code as good examples of this practice.

Related Topic