How to call std::min() when min has been defined as a macro?

后端 未结 5 1848
误落风尘
误落风尘 2020-12-15 15:54

How do I call std::min when min has already been defined as a macro?

5条回答
  •  萌比男神i
    2020-12-15 16:15

    Use #undef min in your code, after #include <> directives.

    #include <...> // bad header that defines `min` macro
    #ifdef min
    #undef min
    #endif
    
    // rest f code.
    

    Addendum: If you need to keep the value of the min macro afterwards, you can disable its definition temporarily using a non-portable solution on some compilers. For instance, Microsoft's C++ compiler has a push_macro pragma that also seems to be supported by GCC.

提交回复
热议问题