C++ include guard

前端 未结 3 1205
轮回少年
轮回少年 2021-01-13 07:10

So I know how to place an include guard in my own header files with the standard

#ifndef ...
#define ...

Now, My question is about includin

相关标签:
3条回答
  • 2021-01-13 07:24

    Include guard use to guard the content inside the guard pair. You can check the system head file string, it also has the include guard. So, don't worry about multiple inclusions.

    0 讨论(0)
  • 2021-01-13 07:31

    The STL library also has include guards and any good library should do the same.

    #ifndef _GLIBCXX_STRING
    #define _GLIBCXX_STRING 1
    

    This is from gcc's

    0 讨论(0)
  • 2021-01-13 07:38

    Assuming that by "STL" you mean the C++ standard library, then you can refer to the C++ standard. §17.6.2.2/2 states:

    A translation unit may include library headers in any order. Each may be included more than once, with no effect different from being included exactly once, except that the effect of including either <cassert> or <assert.h> depends each time on the lexically current definition of NDEBUG.

    This means that it is not necessary to guard against multiple inclusions of the same header.

    0 讨论(0)
提交回复
热议问题