qazmlp wrote:
I need to include a list of
- C++ headers
- headers of other modules
- headers of my module
- implementation specific ie.OS headers
In what order, they should be included in my .CPP file? What is the
best followed approach?
It is all just one opinion:
It is a common rule to include first the standard headers.
Then you include the header for the implementation (like for the class),
which in turn includes all the headers needed for the declaration.
Then you include any additional headers needed for the implementation.
IIRC the only "rule" I have heard is to include the standard headers first.
The cause for this rule is that if there is something "wrong" in your
headers they cannot accidentaly modify the meaning of the standard headers.
Of course, since the other headers might also include standard headers it
can never really be done that all standard headers are included first.
IMHO the order of inclusion is usually a matter of taste. Each header file
in itself must "work" without any other header included before (meaning that
it should include the needed headers, predeclare the needed incomplete types
etc.) So as long as you have no "errors" it is rather a matter of personal
taste and readibility. For example people usually do not mix those headers,
so they first include the standard ones (usually C and C++ headers separated
by a blank line), then (let's say) the OS headers, then the possibly the
other headers needed by the implementation, then the implementation's own
header. I know, it is a different order than I have said before - that is
the reason why I have said that it is /mostly/ a matter of taste or personal
style.
--
Attila aka WW