Should every C or C++ file have an associated header file?

后端 未结 15 2249
情话喂你
情话喂你 2021-02-04 06:30

Should every .C or .cpp file should have a header (.h) file for it?

Suppose there are following C files :

  1. Main.C

  2. Func1.C

  3. <
15条回答
  •  花落未央
    2021-02-04 07:08

    If you want your compiled code to be used from another compilation unit you will need the header files. There are some situations for which you do now need/want to have a headers.

    The first such case are main.c/cpp files. This class is not meant to be included and as such there is no need for a header file.

    In some cases you can have a header file that defines behavior of a set of different implementations that are loaded through a dll that is loaded at runtime. There will be different set of .c/.cpp files that implement variations of the same header. This can be common in plugin systems.

提交回复
热议问题