0
Please explain very slowly in a loud voice....
Can anybody tell me what a Header File actually is and why they are used? What sort of thing goea in them? I have been watxhing a few youtube videos, but a loy of them say "We'll just set up a header file" with no explanation. I don't really know what they are doing! Thanks.
12 Respuestas
+ 7
😆 c++ is a vast beast.
+ 6
lol wait till you start playing with template metaprogramming 😀
+ 2
Hi James. I have been watching the Cavestory link you sent me and that's what has triggered my question. I just wanted tk understand what he was doing and why in a bit more detail. :-D
+ 2
Ah. So it is like creating a library of routines you can call on and add into other programmes as required?? That makes sense!!
OK. so how is that different to setting up another .cpp file or a class?
+ 2
Some times you don't want to show your code to a customer, but he wants to be able to use the code. Then, you create a header for the file, with the interface (usually .h), and another file for the implementation (usually .cc or cpp). You then compile the implementation and provide the .o file to your customer, as well as the header, so he can use it without seeing the implementation. This is just an example of why headers can be separetade from implementation.
+ 1
Header can be considered as a tool kit, it contains many tools like cout, cin in iostream. When you want to use the tools you have take the kit similarly you must include the header file when you want to use the methods that are predefined in them.
+ 1
Dam!! I thought I had this sussed!
I thought a class was a piece of code attached to a specific routine or object and that it was written as an additional .cpp file.
+ 1
I'm having a stroke!
+ 1
I have an example of a fully working programme here from my tutor.
It has loads of header files... one for each thing on the game from the sound to the object to the scrolling. Each header also has a .cpp code file. I am guessing the headers are classes as they have constructors and deconstructors and private variables.
So I am guessong that oncluding the header automatically includes the relevent .cpp code? Even though I can find no mention of it anywhere in the main.cpp?
+ 1
Ok. so a couple more questions:.
what is #pragma?
how do you actually use these classes. I can't find any reference to them in the main code.
+ 1
It's an introduction to C++ with no previous knowledge required. Apparently! I downloaded this app because I had no idea what was going on. I have learnt more from this basic intro and the people on this forum than on the course!