Warning 6.4.1.
If you use the wrong symbols around the filename in your include, the compiler may not find the file because it is looking in the wrong folder.
.cpp
files to include the .h file it using the #include
directive:
main.cpp
(with include)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.) This means that the compiler will know about the doubleValue
function and be able to compile the code in main.cpp
that calls it.
" "
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.
$ g++ main.cpp library.cpp -o program.exe
#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.
#include
directive.
< >
).