Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Mar 5, 2001

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.
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date