Header files

When I was reading the tutorials, I notice I did not see one on header files. Is there a decent tutorial anywhere on header files?
Here is everything you need to know:

When the preprocessor sees

#include <someFile>

it takes the file named someFile and copies it completely into place at that location.

That's more or less it. It's just an easy method of housekeeping. Put into header files anything you think you might want to use a lot and would like a nice easy way to have pasted wholesale into your cpp files.
It might also be worth mentioning that when you get into making classes, it's generally accepted to declare your class (tell the compiler what it looks like) in a header file, and then define your class (tell the compiler what it does) in a cpp file. Usually the files and the classes have the same name.
Is there a more detailed and in-depth tutorial on this?
Seriously, that's all there is. A header file is just C++ code, like your cpp files. Its common to stick declarations in there because that way you can include them everywhere without the compiler complaining about redefining symbols, but if you're looking for a tutorial on header files I've got this bridge I'm selling...
No, not really. It's like this:

Here's your header file:
1
2
3
4
5
6
7
8
class SomeClass{
protected:
    int someInt;
public:
    SomeClass(){};
    void setSomeInt(int);
    int getSomeInt() const;
}


Here's your cpp file:
1
2
3
4
5
6
7
8
9
10
11
#include "SomeClass.h"

void SomeClass::setSomeInt(int inInt)
{
    someInt = inInt;
}

int SomeClass::getSomeInt() const
{
    return someInt;
}


All that you're doing with #include "SomeClass.h" is basically copying SomeClass.h and pasting it into the top of your SomeClass.cpp file.
@ciphermagi
If I was to have another file called main.cpp with the main method in it and wanted to use SomeClass, would I include .h or .cpp?
.h only, and compile the .cpp along with the main.cpp file.
Topic archived. No new replies allowed.