But , header files can also be used to define functions which you can call in the
main.cpp file |
No. While you can do that in your simple example, it does not scale at all. The same applies for both classes and structs.
See
http://www.cplusplus.com/articles/Gw6AC542/
Headers are for declarations so that it is easy to declare the same thing where-ever it is needed. The definition can be in one translation unit only (read: one cpp).
(There is an exception though: template definitions have to be visible.)
Therefore, you will have several cpp-files, and usually a matching header file for each.
When you compile, each cpp-file has to be compiled and all the resulting object files have to be included in the linking phase. IDE's "project" is a list of some sort so it knows what to compile and link, when you click the "compile this project" button. How the list is managed, is up to the IDE.
I don't use IDE, so I can
1. Manually call the compiler (does not scale)
2. Have the list in Makefile (for
make tool) (platform specific)
3. Have the list in formats that GNU autotools / cmake / qmake use to write Makefile (portable).