What is the difference between a .cpp file and a .h file?

user98188 picture user98188 · May 17, 2009 · Viewed 129.4k times · Source

Because I've made .cpp files then transfered them into .h files, the only difference I can find is that you can't #include .cpp files. Is there any difference that I am missing?

Answer

Macker picture Macker · May 17, 2009

The C++ build system (compiler) knows no difference, so it's all one of conventions.

The convention is that .h files are declarations, and .cpp files are definitions.

That's why .h files are #included -- we include the declarations.