Header Files

From ScorecWiki

Jump to: navigation, search

Virtually every .cc file should have an accompanying header file.

Include guard

Make sure every header file has an include guard (http://en.wikipedia.org/wiki/Include_guard)

Example:

#ifndef H_FOO
#define H_FOO

// code goes here

#endif

Naming and Ordering of Includes

Only include other header files that are used in your header file.

/// C library Includes
/// C++ library Includes
/// Other libraries .h files
/// Your project's .h files

Put forward declarations and using declarations after the includes. In any foo.cc that implements foo.h, put foo.h before any other includes. Within each of the above sections, try to order the includes alphabetically. All your project's code should be in one source directory, and header files should be listed in terms of their path within that directory (Not sure if this is a good idea.). For example, a header file foo.h in src/dir1/dir2, where src is the source directory, should be included as:

#include "dir1/dir2/foo.h"
Personal tools