When you use a class
in name only, you don't need to
#include
the header that defines it. Instead, you can just declare it as a forward reference:
class SomeClass;
A header that contains this declaration can now declare functions with a parameter or result whose type is a
pointer or a
reference to
SomeClass
. This is a common approach for resolving what would otherwise be a circular dependency.
In name only means that the compiler doesn't need to know the
size of
SomeClass
. It is only being accessed through a pointer or reference, and the size of the pointer or reference is known to be either 32 or 64 bits.
The
.cpp that implements one of these functions will have to
#include
the header that defines
SomeClass
, but this won't cause a circular dependency because all
.cpps are leaves in the dependency graph.