Making Sure a Header File Gets Included Only Once - C++ Preprocessor

C++ examples for Preprocessor:Directive

Introduction

#define a macro in your header file, and include only the contents of the header file if the macro hasn't been defined.

You can use this combination of the #ifndef, #define, and #endif preprocessor directives.

#ifndef MYCLASS_H__ // #include guards
#define MYCLASS_H__

     // Put everything here...

#endif // MYCLASS_H__

Related Tutorials