PDA

View Full Version : header


bootyburglar
09-10-2003, 06:20 PM
Hello, im a little confused about including functions and classes using header files, basically, how do i create (and use in another cpp project) a header file.


ENVIROMENT

Dev c++ ver 4

stuka
09-11-2003, 11:02 AM
Step 1 - create a header file that declares your classes/functions/constants for use.
Step 2 - create a source (.cpp) file that defines the classes/functions/constants.
Step 3 - compile the source file to get an object (.o) file.
Step 4 - create the 'client' code that calls the functions, uses the classes, from the .o file - this file will #include the header file.
Step 5 - compile the 'client' code
Step 6 - link the compiled 'client' code and the 'library' code into an executable.

Jamaican
09-12-2003, 04:20 PM
I use Dev C++ too, anyways, enough with the small talk

this is what you can do

1) write definitions of fucntions, classes, etc
2) save it as a ".h" file (.h is for header files, and do not use "main()" in it if because you will use the main() function is your cpp file. if you use it both places it will cause an error)
3) create your source file (the one with the function's/class's declarations

to use the header file: at the "include" section of your source file, inlcude your header file with quotation marks NOT greater than and less than sign, like this:

#include "your header file"

not like this:

#include <your header file>

the reason for the guotation marks and not less than and greater than signs is that '<' and '>' tells the compiler that the
header file you specified is a library function (which its not)
but the " " tells the compiler that the header file(s) is actually
not a library function but a "home-made" file.

4) save it as a ".cpp" file and compile