Should Includes Be in Header or Cpp?

2 Answers. In general, you should only include headers in . h files that are needed by those headers. In other words, if types are used in a header and declared elsewhere, those headers should be included.

Should you put includes in header file?

A header file should be included only when a forward declaration would not do the job. The header file should be so designed that the order of header file inclusion is not important.

Should headers include other headers?

4.3 A header file must be self-contained and self-sufficient. ... Must include all other headers and/or forward declarations it needs to be compiled standalone. In addition, a file should not rely on symbols defined in other header files it includes; the other files should be included explicitly.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.