Don’t Put All Includes in the .hxx

Ok, one more thing about headers, then I promise to talk about something else.

Just because a header file is called a header file, you shouldn’t include all your headers there. Often, a source file, where the definition of you functions and/or classes are, need quite a lot of headers to do its work. It might for instance need <algorithm> to do some sorting or searching, a fact your declarations don’t need to worry about:


#include "MyType.hxx"

void process(MyType obj);

#include "processing.hxx"
#include <algorithm>

void process(MyType obj) {

You almost always need to include some headers in the .hxx, so why not put them all there? While compiling your .cc file, it doesn’t really matter, since all those files are included anyway. But when someone else includes your header, they suddenly depend on everything your implementation depends on. This also adds to compilation time for your users. So do your includes as listed above, don’t move

3 thoughts on “Don’t Put All Includes in the .hxx

  1. Hiya very nice blog!! Man .. Beautiful .. Superb ..
    I’ll bookmark your web site and take the feeds also?
    I am satisfied to find a lot of useful information here in the publish,
    we’d like develop extra techniques in this regard, thank you for sharing.

    . . . . .

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s