The Difference of a .H sfile and .C sfile

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
.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:
 
int sum(int a,int b);

sum.cpp:
1
2
3
int sum(int a,int b){
    return a+b;
}
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?
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.
Topic archived. No new replies allowed.