In short:
Header files are just more files that you can 'include' into your source code files. They normally (but don't have to) have interface declarations, so that each file knows that the so-and-so code exists somewhere else in your program, and you don't get compilation errors (unless, of course, the code doesn't exist). They are called header files because they are normally included at the 'head' (front, top) of your source code files.
A library is source code, rather than Header Files which are just definitions. However, a library is a combination of header files and source files, and some libraries (for example, Boost) can be pretty much header only.
A namespace is an actual C++ construct that separates the names of functions, classes and variables from each other, to prevent naming conflicts. For example:
1 2 3 4 5 6 7
|
namespace a {
void func() { std::cout << "Hello World!"; }
}
namespace b {
void func() { std::cout << "Goodbye Everybode!"; }
}
|
In the above code, if the two
func()s weren't in namespaces, you would end up with errors (because you have given it two different definitions). However, with namespaces, you can specify that you want, for example, the
func() in
a by calling
a::func(). An example that you should know of is the
std namespace, such as in
std::cout.