Include guard and #pragma once in the same header file

前端 未结 1 683
孤城傲影
孤城傲影 2021-01-21 06:30

Quoting from Microsoft documentation, There is no advantage to use of both the #include guard idiom and #pragma once in the same file.

Answers to previous r

相关标签:
1条回答
  • 2021-01-21 07:08

    Technically #pragma once is not standard C++, whereas header guards are. They will not conflict with each other if you have both.

    The reason boost likely has both, as alluded to by the #if defined(_MSC_VER) is that if you're not using MSVC then you need something to act as your header guard, so they fall back to the other method.

    Since boost strives to be cross-platform they are trying to ensure their code works on compilers that don't support #pragma once, though all of the big modern compilers I can think of do support it, as enumerated on wikipedia.

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