When the compiler is working on main.cpp, it will see the #include "library.h" directive and read the contents of library.h into that location. (Including a file essentially copies the contents of that file into the including file.)
Doing this ensures that when the compiler hits the call to the doubleValue function on line 10, it has already seen the declaration for that function from the included library.h file.
Note that this use of include uses " " around the name of the file to include instead of < >. The angle brackets say “this is a standard library, look for it with the compiler’s file”. The quotes say “this is a library that is NOT part of the standard compiler libraries, look for it in our files”. We use #include <iostream> because iostream is a standard library. Our library.h file is not.
The compiler does not need to be told to build the header (as it is included into the .cpp files that need it to build). So our recipe to build a program code would make no mention of the header file:
Generally, a .cpp file will include it’s own .h - we would put #include "library.h" in the library.cpp file as well as the main file. This means that the code from the header file would be used as part of compiling both .cpp files. This is why the header can only contain declarations, not definitions. We need to make sure that we do not have two copies of any function’s definition.
Making a .cpp/.h file pair for the code and header is the most common way to build a code library in C++. However, the code in this book does not use the header file strategy in order to minimize the number of “files” that need to be defined in the text. Instead, we will rely on modules, which are discussed next.