Today, a colleague inquired if there is a technical reason to #include headers before forward declaring a class in a header. Specifically, I'm not interested in the order of #includes
within themselves or the merits of forward declare
vs #includes
, but on any technical reasons one order is preferred over the other.
Example: Assume companions.h
is correct in that it requires donna.h
and clara.h
to be #include
and CSpaceTimeContinuum
and CTardis
can be forward declared. Is it better to #include then forward declare?
// companions.h
#include "donna.h"
#include "clara.h"
class CSpaceTimeContinuum;
class CTardis;
or forward declare then #include?
// companions.h
class CSpaceTimeContinuum;
class CTardis;
#include "donna.h"
#include "clara.h"
If there's no technical difference and it is a stylistic thing only, I would be happy to learn that as well. Thank you!