c++ - Should I always split my files into declarations (.h) and definitions (.cpp) -


to make code easier read splitting across several files. 1 of files contains 2 initialisation methods. worth creating .h the declaration methods in, , including that, or should include .cpp straight off, 2 methods, worth conforming standard?

you should never include cpp file, no matter how few definitions in them: each definition included in several other cpp files produce duplicate symbols, causing linking errors.

if build class used in multiple translation units (that's fancy name cpp files) should build header it. templates go without cpp file - header necessary.

although common practice make 1 cpp/header pair each class, ok include multiple related classes in single translation unit, , put declarations in single header.


Comments