About Namespaces and Header Files
I'll keep this short and sweet.
Namespace
"A namespace is a mechanism in C++ for avoiding problems
that can arise when duplicate names are used in a program for different things, and it does this
by associating a given set of names such as those from the standard library with a sort of family name,
which is the namespace name." (Horton Beginning Visual C++ 2008 p43)
Header file
The <iostream> file is
called a header file because itâs usually brought in at the beginning of a program file. The <iostream>
header file contains definitions that are necessary for you to be able to use C++ input and output statements.(Horton Beginning Visual C++ 2008 p43)
so for example let's say you wanted to use the command cout.
If you don't have a namespace declared then you have to fully qualify the name so: std::cout
This shows that cout resides within the namespace std. If you don't want to have to type the fully qualified name every time you use it then you have two options.
1. a using declaration ex. using std::cout;
or
2. a using definition ex using namespace std;
Summary: Header files contain function definitions, etc
Namespaces help to prevent confusing in case variables have the same name.
|