Friday, August 8, 2014

Order of #include headers

First, I define four types of headers. These categories do not cover everything (such as .inl or .tpp, or whatever you want to call files that you may store templates in (I don't do this)).

1) Local Headers

These are usually headers you have created for your project.

IE

#include "TeddyBear.h

2) Third Party Libraries

These are libraries such as Boost or pugixml.

3) Standard Library

These are headers from the C or C++ Standard Library.

IE

#include <string>

4) Platform-specific libraries

These are libraries specific to your operating system.

IE

#include <windows.h>

I organize my headers in the order that I posted all of these categories. Within each category, I organize the headers alphabetically. Reasons why I organize them by these categories will be posted in the future (it's not just an arbitrary decision).

There are exceptions. On Windows, if you use pre-compiled headers (#include "stdafx.h"), you will need to put those at the top of your CPP files or else the compiler will cry.