V
vsgdp
I was looking at some library code today and noticed something like
this:
// sublibrary.h
// define some constants, enums, symbols
#include "componentA.h"
#include "componentB.h"
#include "componentC.h"
#include "componentD.h"
Then each componentX.h file #includes sublibrary.h in order to get the
defined constants, enums and such. At first I thought this would be a
problem because it seemed circular, however, it works because each
component header file #includes "sublibrary.h" outside the inclusion
guards:
// example: componentA.h
#include "sublibrary.h"
#ifndef COMPONENTA_H
#define COMPONENTA_H
// class of ComponentA
#endif
If #include "sublibrary.h" was inside the inclusion guards, it would
not work since ComponentA would get defined twice.
So my question is: Is this style common or generally recommended?
this:
// sublibrary.h
// define some constants, enums, symbols
#include "componentA.h"
#include "componentB.h"
#include "componentC.h"
#include "componentD.h"
Then each componentX.h file #includes sublibrary.h in order to get the
defined constants, enums and such. At first I thought this would be a
problem because it seemed circular, however, it works because each
component header file #includes "sublibrary.h" outside the inclusion
guards:
// example: componentA.h
#include "sublibrary.h"
#ifndef COMPONENTA_H
#define COMPONENTA_H
// class of ComponentA
#endif
If #include "sublibrary.h" was inside the inclusion guards, it would
not work since ComponentA would get defined twice.
So my question is: Is this style common or generally recommended?