Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Header order [closed]

What order should headers be declared in a header / cpp file? Obviously those that are required by subsequent headers should be earlier and class specific headers should be in cpp scope not header scope, but is there a set order convention / best practice?

like image 525
Konrad Avatar asked Mar 05 '09 10:03

Konrad


People also ask

Does order of header files matter in C?

Does the include order matter? If your header files are self-contained, then the include order technically shouldn't matter at all for the compilation result.

What are system headers C++?

In C++ program has the header file which stands for input and output stream used to take input with the help of “cin” and “cout” respectively. There are of 2 types of header file: Pre-existing header files: Files which are already available in C/C++ compiler we just need to import them.

Can C program run without header file?

Yes you can wirte a program without #include , but it will increase the complexity of the programmer means user have to write down all the functions manually he want to use.It takes a lot of time and careful attention while write long programs.


1 Answers

In a header file you have to include ALL the headers to make it compilable. And don't forget to use forward declarations instead of some headers.

In a source file:

  • corresponded header file
  • necessary project headers
  • 3rd party libraries headers
  • standard libraries headers
  • system headers

In that order you will not miss any of your header files that forgot to include libraries by their own.

like image 130
Mykola Golubyev Avatar answered Sep 23 '22 01:09

Mykola Golubyev