Using the C/C++ Preprocessor

Basic Reference

Preprocessor Overview

Interface vs Implementation

Why file.cpp has a #include of its own .h File

Who Sees What and Why?

Suppose we have
  • In order to::

    Include Files

    Adding a #Include Guard (Macro Guard)

    Wiki Reference

    The Problem — Preventing multiple inclusions of the same .h file

    The following code is illegal — it causes a duplicate declaration compilation error:
    class C {
    ...
    };
    ...
    class C {
    ...
    };
    

    This presents the following problem:

    The above code suffers from the same duplicate class definition problem as above.

    The Solution: Include Guards

  • To prevent this, we prevent the same .h file from being included more than once

    Other uses of conditional compilation