Include guards prevent multiple includes of the same file in C++, MFC.
They are preprocessor directives. Pre-processor directives will be also called as compiler directives. These are instructions that will not be part of the executable/object file instead commands to the compiler when it generates the executable!
When you require include guards?
When you get “redefinition; different storage class” errors in your visual studio it means that same header file is included twice somewhere directly or indirectly. This will be difficult to find in complex code. So easy option is to provide include guard for your most used header files. Syntax given below…
#ifndef YOURFILENAME_H
#DEFINE YOURFILENAME_H
//YOUR HEADER FILE CODE GOES HERE
#endif
No comments:
Post a Comment