The Include Guard

The first new feature in this header file doesn't have anything to do with adding new functionality. Instead, it is a means of preventing problems if we #include this header twice. I'm referring to the two lines at the very beginning of the file and the last line at the end of the file. The first of these lines,

#ifndef XSTRING_H

uses a preprocessor directive called #ifndef (short for “if not defined”) to determine whether we've already defined a preprocessor symbol called XSTRING_H. If we have already defined this symbol, the compiler will ignore the rest of the file until it sees a #endif (which in this case is at the end of the file).

The next line,

#define XSTRING_H

defines the same preprocessor symbol, XSTRING_H, that ...

Get C++: A Dialog Programming with the C++ Standard Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.