Possible problems with NOMINMAX on Visual C++

前端 未结 4 1931
青春惊慌失措
青春惊慌失措 2020-11-29 05:18

What problems could I get when defining NOMINMAX before anything else in my program?

As far as I know, this will make not

4条回答
  •  囚心锁ツ
    2020-11-29 05:48

    I generally use NOMINMAX like this to limit the potential side effects:

    #define NOMINMAX
    #include 
    #undef NOMINMAX
    

    That way the scope of the NOMINMAX is relatively confined.

    It's not a perfect solution. If something else has already defined NOMINMAX, this pattern fails (though I've never encountered such a case).

    If you want to be really, really careful, then you can #include a wrapper header wherever you would have #included windows.h. The wrapper would go something like this:

    /* Include this file instead of including  directly. */
    #ifdef NOMINMAX
    #include 
    #else
    #define NOMINMAX
    #include 
    #undef NOMINMAX
    #endif
    

    You could imagine doing other things in the wrapper, too, like enforcing UNICODE and/or STRICT.

提交回复
热议问题