What You Should Include in a Header File

A header file should begin and end with #include guards to guarantee that it’s not #included more than once during the same compilation session. A typical #include guard looks as follows:

 // from stdlib.h#ifndef STDLIB_INCLUDED // included for  the first time?#define STDLIB_INCLUDED// declarations, typedef's etc.#endif // close #include guard at the end of the file


Inside the header file, you may insert function prototypes, structs declarations, #define macros, enum types, typedef’s, class declarations, extern declarations of global objects, template classes and functions, constants, certain #pragma directives that control the compilation process and similar macro directives. Note, however, that a header file should never have definitions (except for macros and templates). In other words, you shouldn’t implement functions and class member functions inside a header file (except for inline functions), nor should you create variables, arrays, and object or global variables in a header file.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: