Looking around at different code bases I see a variety of styles:
-
Class “interfaces” defined in header file and the actual impl in a cpp file. In this approach the headers look well defined and easy to read but the cpp files look confusing as it’s just a list of methods.
-
The second approach i see is just to put everything in a single class cpp file. These class files contain the definition and actual method impls in the body of the class definition. This approach looks better to me (more like Java and c#).
Which style should I be using?
For all but the simplest programs, style #2 is simply impossible. If you
#includea.cppfile with function definitions from multiple other.cppfiles, the definitions get added to multiple object files (.o/.obj) and the linker will complain about clashing symbols.Use style #1 and learn to live with the confusion.