macro and member function conflict

前端 未结 5 553
名媛妹妹
名媛妹妹 2020-12-05 18:05

I have problem that,std::numeric_limits::min() conflicts with the \"min\" macro defined in \"windef.h\". Is there any way to resolve this conflict without undefine the \"mi

5条回答
  •  囚心锁ツ
    2020-12-05 18:26

    The only really general solution is to not include windows.h in your headers.

    That header is a killer, and does pretty much anything it can to make your code blow up. It won't compile without MSVC language extensions enabled, and it is the worst example of macro abuse I've ever seen.

    Include it in a single .cpp file, and then expose wrappers in a header, which the rest of your code can use. If windows.h isn't visible, it can't conflict with your names.

    For the min/max case specifically, you can #define NOMINMAX before including windows.h. It will then not define those specific macros.

提交回复
热议问题