This section of the archives stores flipcode's complete Developer Toolbox collection,
featuring a variety of mini-articles and source code contributions from our readers.

Minimize Recompilation When Using Inlines
Submitted by

Most of my classes have inlined methods : Get/Set, operators, simple
constructors, etc. For the sake of readability I'm in the habit of separating
their implementation from the declaration of the class, by putting them in a
.inl file (the MFC way). The .inl file is included at the end of the .h file, so
apart from the aesthetic consideration it is exactly the same thing as coding
the functions'bodies in the class itself : if a single inlined function is
modified, every .cpp file including this class directly or not is going to be
recompiled, which can take some time in a big project.

Considering that I develop most of the time in debug mode (and compile in
release when everything seems OK), and that functions are by default not inlined
at all in debug mode under Visual C++, there is a solution to minimize the
recompilation problem : put the functions to be inlined in the .cpp file for a
debug build, and in the .h file for a release build (so that they can really be
inlined). Let's take an example to see how this works ; suppose I have the
following class :

As stated before, any modification in VectMat.inl will cause the recompilation of every .cpp file that includes
VectMat.h, and vectors
are the kind of classes that are used in a lot of places. Now let's see the modified version :