[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppIncludeGuard
An implementation file (.cpp) does not have #include guards, because they do not get #included, but 'Added to Project' instead.
Always write internal #include guards [1]. Never write external #include guards [1].
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppIncludeGuard
(C++) #include guard
This preprocessor statements #ifndef ,#define and #endif can be used for #include guards. These prevent a header file (.h) to be #included multiple times, causing a redeclaration error.An #include guard
//Your header (.h) file
- ifndef __MYHEADERFILE_H
- define __MYHEADERFILE_H
- endif
An implementation file (.cpp) does not have #include guards, because they do not get #included, but 'Added to Project' instead.
Always write internal #include guards [1]. Never write external #include guards [1].
'#include guard' links
Reference
- 1) Herb Sutter and Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. ISBN: 0-32-111358-6. Chapter 24: 'Always write internal #include guards. Never write external #include guards'.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
