Header files?

Hi guys
Ive been searching on the web for a while know trying to find out exactly what code to include in header files whenever I search I just find lots of different people saying lots of different things. I want to know if I should include class and function definitions in my header files or class and function declarations? Also I don't see the advantage of just including declarations in the header files so if someone could try and explain this to me I would be most grateful
Hello Macz1,
You can look at this article

http://cplusplus.com/forum/articles/10627/
if i understood you correctly
Firstly,you create a new file:
Examlpe "Vetor.h"
after writing a code
when you use it
you need declare:#include"Vector.h"
good luck
i hope it usefully.
Thanks guys for the responses firix that link is excellent so thank you
Tuandt5 that was helpful too

Thanks
Hey guys I'm back after reading the article that firix recommended, which was helpful but it still left me confused as to what you put in header files is it class/function declarations or definintions
it explains everything.


   do nothing if: A makes no references at all to B
-  do nothing if: The only reference to B is in a friend declaration
-  forward declare B if: A contains a B pointer or reference: B* myb;
-  forward declare B if: one or more functions has a B object/pointer/reference
   as a parementer, or as a return type: B MyFunction(B myb);
-  #include "b.h" if: B is a parent class of A
-  #include "b.h" if: A contains a B object: B myb;


Last edited on
- Class bodies go in header files
- Function prototypes go in header files
- Inline function bodies go in header files
- Template function bodies go in header files
- non-inline, non-template function bodies go in .cpp files.


(Generally. There are, of course, exceptions to the above rules)
Last edited on
You make headers to get a cleaner code and faster compiling, and also in case you want to export functions, classes, templates to other programs
You can look at the standard header file.

http://msdn.microsoft.com/en-us/library/a7tkse1h.aspx
Topic archived. No new replies allowed.