0

Possible Duplicate:
C++ Header order

My question is about includes in .h files. Is it preferable to include first all the standard headers like iostream and only after that all users header files, or vice versa? I have googled for some time, but have not found any recommendations.

Community
  • 1
  • 1
besworland
  • 747
  • 2
  • 7
  • 17

5 Answers5

7

Its a personal choice, I use it in following order:

<standard headers>
<platform headers>
<project headers>
Asha
  • 11,002
  • 6
  • 44
  • 66
2

My personal preference is to go from the bottom up. So platform-specific header files go first, C++ standard header files would go next, then core libraries (like boost), then higher-level libraries (like databases), then project-specific includes.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278
  • Well, the point is that I have also read the same info in Herbert Schildt book, but my boss said me yesterday that it is a "bad coding style"... Anyway thank you for the attention. – besworland Mar 07 '12 at 09:04
0

A *.cc file should first #include system headers, then user's headers (otherwise name clashes between system libraries and your own code will have strange behavior; but you should avoid such clashes). But you could put all the #include in your header file.

You may decide to have a single user header containing all the #include for system headers needed by your application; this facilitates, when compiling with GCC on Linux, pre-compiled headers. See this answer.

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
0

There is already a topic about this:

C++ Header order

But in general you have to ensure that there is no importance in the order of the headers.

Community
  • 1
  • 1
Mentezza
  • 627
  • 5
  • 16
0

The order of the include doesn't matter, you can start with whatever you want and end also.

I don't know if i answered correctly, that's what i understood...

Zeina
  • 1,573
  • 2
  • 24
  • 34