Include one header file in each source file

后端 未结 4 574
心在旅途
心在旅途 2021-01-19 14:50

Say you have 100s of source files (.c or .cpp) files, and you want to include some definitions, function/variable declarations in each of them. Normally in C/C++, you use he

4条回答
  •  耶瑟儿~
    2021-01-19 15:45

    Header files are not definitions - they are declarations.

    You put as few in as possible - saves the compiler work and also inter-dependencies.

    You can even reduce the number further by using forward declarations in those header files.

    If you are clever you can get you IDE to help you out with filling in the gaps instead of hurting your fingers.

提交回复
热议问题