Ian Collins said:
Hardly, unless your build system is grossly underspecified.
Unnecessary includes won't have a significant effect on compile times - but
they can certainly hurt build times.
Suppose a method in class Foo accepts arguments of class Bar, but Foo isn't
a subclass of Bar. If we "#include "Bar.h"" in Foo.h, that creates a chain
of dependencies, where any file that includes Foo.h also becomes dependent
on Bar.h. Classes that include Foo.h, but never call the method that takes
Bar arguments, or work with instances of Bar in any way, will still have to
be recompiled when Bar.h is modified.
On the other hand, if we forward declare "class Bar" in Foo.h, and move the
include into Foo.cc, that eliminates the unnecessary dependencies. A change
in Bar.h will still trigger a compile of Foo.cc, of course, but not of other
files that happen to include Foo.h, but don't need the full definition of
Bar.
In both cases, the compile time for Foo.cc is more or less identical. But
the time for the incremental build after changing Foo.h will be improved
by eliminating the unnecessary include.
sherm--