Prevent multiple inclusions of header files using #ifndef.
In a C++ project, it's common for a header file to be included by multiple source files. It's also possible for one header file to include another, leading to a situation where a single source file might indirectly include the same header file more than once. If a header file contains definitions (like class definitions), including it multiple times in the same translation unit will lead to a redefinition error from the compiler. To prevent this, we use a standard preprocessor technique called **header guards**. The structure is simple and should be used in every header file you write. At the very top of the header file (e.g., `myheader.h`), you add the following lines: `#ifndef MYHEADER_H` `#define MYHEADER_H`. Then, at the very bottom of the file, you add: `#endif // MYHEADER_H`. Here's how it works: The first time the preprocessor sees this file, the macro `MYHEADER_H` has not been defined yet. So, `#ifndef MYHEADER_H` (if not defined) is true. The preprocessor then proceeds to the next line, `#define MYHEADER_H`, which defines the macro. It then includes the entire content of the header file until it hits the `#endif`. If the preprocessor encounters an `#include "myheader.h"` again in the same compilation process, it will check `#ifndef MYHEADER_H` again. This time, since `MYHEADER_H` is already defined, the condition will be false, and the preprocessor will skip everything down to the `#endif`, effectively ignoring the entire contents of the file and preventing a redefinition error. The macro name (`MYHEADER_H`) must be unique across the project.