Skip to content

Instantly share code, notes, and snippets.

@vibhoraggarwal
Created February 19, 2020 12:16
Show Gist options
  • Save vibhoraggarwal/f69812160ff6a4530e5ae3827b84df38 to your computer and use it in GitHub Desktop.
Save vibhoraggarwal/f69812160ff6a4530e5ae3827b84df38 to your computer and use it in GitHub Desktop.

Header files (.h) are designed to provide the information that will be needed in multiple files. Things like class declarations, function prototypes, and enumerations typically go in header files. In a word, "definitions".

Code files (.cpp) are designed to provide the implementation information that only needs to be known in one file. In general, function bodies, and internal variables that should/will never be accessed by other modules, are what belong in .cpp files. In a word, "implementations".

The simplest question to ask yourself to determine what belongs where is "if I change this, will I have to change code in other files to make things compile again?" If the answer is "yes" it probably belongs in the header file; if the answer is "no" it probably belongs in the code file.

Reference :

  1. https://stackoverflow.com/questions/1945846/what-should-go-into-an-h-file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment