Item 62. Include Guards

Production C++ applications tend to use a lot of header files, and many header files include other header files. Under these circumstances, it’s common for the same header file to be indirectly included more than once in a compilation, and it’s not uncommon in large, complex applications for the same header file to occur hundreds of times in the same compilation. Consider the simple case of a header file hdr2.h that includes another header file, hdr1.h, and a header file hdr3.h that also includes hdr1.h. If both hdr2.h and hdr3.h are included in the same source file, hdr1.h will be included twice. Typically, such multiple inclusions are undesirable and cause multiple definition errors.

For this reason, C++ header files ...

Get C++ Common Knowledge: Essential Intermediate Programming 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.