Header files- newbie needs lil help!
I''m learning C++, and we just got to the part where the author reccamends using header files. He says to save the file as a name.hpp file, but this is totally confusing! 1) what is a header file, and 2.) how do I use header files in my applications?
3D Math- The type of mathematics that'll put hair on your chest!
Header files are pretty useful things, as you continue learning C and C++... though as far as I''ve seen, the correct extension for header files is usually .h (.hpp works but I''ve never seen anyone use it)
Header files are nice for declaring things like global variables and defines when you are programming in C. In C++, header files hold global variables and defines, as well as the declarations of classes, and the entire declaration and implementation of templates, as well as some other random things. For instance, in C, if you have a variable like "screenWidth" in a header file named globals.h, you might want to declare it in your header, then you can use it in any C file you might want that variable in, just by saying
#include "globals.h"
at the top of your C file.
-fel
Header files are nice for declaring things like global variables and defines when you are programming in C. In C++, header files hold global variables and defines, as well as the declarations of classes, and the entire declaration and implementation of templates, as well as some other random things. For instance, in C, if you have a variable like "screenWidth" in a header file named globals.h, you might want to declare it in your header, then you can use it in any C file you might want that variable in, just by saying
#include "globals.h"
at the top of your C file.
-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
a header file is another file that has some of the program''s code in. you can stick templatized classes in header files. i think they are mainly for organizing your code. you can probably use them like you can with .cpp files.
i may be wrong, so check with someone else
i may be wrong, so check with someone else
From a hard Computer Science standpoint:
The theory of header files is that define the interface to some set of functionality. That includes function prototypes, class declarations, constants, globals, etc. The c files then define the implemenation of the exposed interface. Any file that wishes to access the exposed functionality includes the header file, and the linker takes care of making available the implementation.
That way, only when there is a change in the interface (the header file) are other files that use that functionality affected. If the implementation of the functionality changes (the c file) then the other files that use the functionality are unaffected.
And this is why one of professors in college *hated* Java. No interface/implementation source distinction.
The theory of header files is that define the interface to some set of functionality. That includes function prototypes, class declarations, constants, globals, etc. The c files then define the implemenation of the exposed interface. Any file that wishes to access the exposed functionality includes the header file, and the linker takes care of making available the implementation.
That way, only when there is a change in the interface (the header file) are other files that use that functionality affected. If the implementation of the functionality changes (the c file) then the other files that use the functionality are unaffected.
And this is why one of professors in college *hated* Java. No interface/implementation source distinction.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement