C++ #include guards

后端 未结 8 865
鱼传尺愫
鱼传尺愫 2020-11-22 13:24

SOLVED

What really helped me was that I could #include headers in the .cpp file with out causing the redefined error.


I\'m new to C++ but I have some p

8条回答
  •  庸人自扰
    2020-11-22 13:42

    " #pragma once " ::: serves the same purpose as header guards, and has the added benefit of being shorter and less error-prone.

    Many compilers support a simpler, alternate form of header guards using the #pragma directive: " #pragma once " // your code here

    However, #pragma once is not an official part of the C++ language, and not all compilers support it (although most modern compilers do).

    For compatibility purposes, people recommend sticking to traditional header guards. They aren’t much more work and they’re guaranteed to be supported on all compliant compilers.

提交回复
热议问题