Remove #pragma once warnings

前端 未结 2 708
死守一世寂寞
死守一世寂寞 2020-12-16 04:59

I am using #pragma once in my .cpps and .hpps and because of that I get a warning for each file that uses it. I have not found any opt

相关标签:
2条回答
  • 2020-12-16 05:28

    Indeed the #ifndef guard can always be used, but just to remove the warning while compiling the source which uses #pragma once I would recommend to use the -woption while compiling.

    e.g. gcc -w -o <output file> <input file(s)>

    0 讨论(0)
  • 2020-12-16 05:37

    The common approach is to place the guard in the .h file only:

    #ifndef MYFILE_H
    #define MYFILE_H
    // all your myfile.hpp here
    #endif
    

    or

    #pragma once
    // all your myfile.hpp here
    

    The rest of files (other .cpp) should do nothing regarding the guards. You should not get warnings by doing this.

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