1. Introduction
Header files usually have the declarations required by the definitions. Say for example a class template and its layout is specified in the header file. This layout will just have variable and function names with their scopes. The implementation file actually makes use of the variables and links them with the function implementation.
2. Including the header file
Header files are referred by the implementation files by using the #include pre-processor directive. The file name extension for the header file is .h and some old C style programmer uses .hpp also. The implementation file with an extension .cpp refers these header files to know the declarations. So if we have some common declarations required for more than one implementation groups, we do refer the same header file for both the implementation files.
You can include the header file in two different ways.
1) Using the <>
2) Using the “”
Below are the examples for it:
#include "stdafx.h"
#include <conio.h>
In the below section we will see the difference.
3. Two types of inclusion
The header file specified in between the angle braces <> tells that the header file is part of the c++ libraries. The preprocessor will search for the file first in the IDE specific paths and then in the path specified path the compiler switch /I. This is shown below:
The project property shows where you can set this /I option.
OK. What about the other option, which is using the header between double quotes? In that case the compiler will search for the current directory of the file that has the #include statement. When the referred header file is not found, then it searches the file like it did for the <> braces.