| xstabless (11) | |
|
I'm still pretty new to this but i've been learning quite a bit but don't understand the difference of a .h and .c files what are the difference and how you know when to use them. Thnx | |
|
Last edited on
|
|
| helios (9442) | |||||
|
.h* are used for declarations (functions, classes, globals, constants, etc.). .c* are used for definitions (i.e. implementations). For example, for the function sum: sum.h:
sum.cpp:
| |||||
|
|
|||||
| Umz (205) | |
|
Just outta interest, if I had a file that was built purely of functions I could save it in a .cpp file and include it in the main program file right? Also if I need to use inheritance would I be better off using a .h for the base class and the different .h files for the classes that inherit? | |
|
|
|
| helios (9442) | |
|
No. .cpp aren't included by other files. They are compiled separately and then their respective object files are linked by the linker. That's what I do. A habit I picked up from Java. There isn't much difference; It's basically a matter of personal style. | |
|
|
|