Why it's valid to include a header file twice in c++?

后端 未结 7 887
迷失自我
迷失自我 2021-02-09 17:25
#include \"DLLDefines.h\"
#include \"DLLDefines.h\"

The above actually passed compilation, but why?

7条回答
  •  粉色の甜心
    2021-02-09 18:21

    It depends on the header file; there is no language restriction on multiple includes of the same file.

    Some files are designed to be included multiple times (e.g. can be included multiple times to turn 'on' and 'off' assert).

    Many files are safe to be included multiple times because they have include guards, others are not and should be included only once in a translation unit or even a program.

提交回复
热议问题