Alex Rivera | Logout

When should I not split my code into header and source files?

Asked 2011-10-18T10:23:40.800
9

I know this maybe quite subjective, but are there any general rules for situations when it is not necessary for code to be split into two files?

For example is the class is extremely small, or if the file simply holds some global definitions or static functions? Also, in these cases, should the single file be a .cpp file or a .h file?

Edit
Report

1 Answer

0

I know this maybe quite subjective, but are there any general rules for situations when it is not necessary for code to be split into two files?

Split the code into header and source whenever you can.

Generally, this shouldn't be done in next cases :

  • the code consists of template classes and functions (unless you explicitly instantiate templates in the source file)
  • the header consists only of inline functions

should the single file be a .cpp file or a .h file?

Should be the header file (.h).

answered 2011-10-18T10:33:04.753

Your Answer