721
edits
Line 19: | Line 19: | ||
=Session 3: File Structuring, Preprocessor, Compiler & Linker= | =Session 3: File Structuring, Preprocessor, Compiler & Linker= | ||
To make good use of C++, we need to structure our code in header files (.h) and source files (.cpp). | To make good use of C++, we need to structure our code in header files (.h) and source files (.cpp). | ||
The idea is, that every source file acts like a wheel in our machinery that does only one thing and can be reused in other spots of our code to solve the same problem if it must. Furthermore, by structering our code in | The idea is, that every source file acts like a wheel in our machinery, that does only one thing and can be reused in other spots of our code to solve the same problem, if it must. | ||
Furthermore, by structering our code in nice little modules, the compiler has less work to do, since it only needs to compile the modules that we work on and that we changed. Note that only the source files get explicitly compiled! The headers are directly copied into the source files by the preprocessor and act as an index to point to the other source files as depicted below. | |||
Think of the headers as a table of contents that helps the programmers and the compiler and linker to know where the functions in the source files reside. | |||
[[File:filestructure_preprocessing_compilation1.png|800px]] | [[File:filestructure_preprocessing_compilation1.png|800px]] |