1

Is there any standard order of inclusion to avoid hidden dependencies?

if yes,is this correct order?

  1. C library headers
  2. C++ library headers
  3. Other library headers
  4. Related headers
  5. our projects headers
Anoop pS
  • 105
  • 5
  • 1
    Always include your own header first - so `foo.cc` includes `foo.hh` first. That ensures that `foo.hh` is self-contained and does not depend on `foo.cc` including other headers for it. – Jesper Juhl Jul 05 '16 at 11:38

1 Answers1

4

There is no standard order, but if you want to avoid hidden dependencies, you have to go in the exact opposite order: include the most project-specific headers first, then specific library headers, then more generic library headers (such as e.g. Qt and boost), and eventually standard library headers last.

This way, you will be certain that missing dependencies of your project's headers are not accidentally satisfied by the headers which you've included earlier.

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455