取消定义最小和最大宏

时间:2014-01-31 14:56:55

标签: c++ c-preprocessor

在源代码中,我看到min和max未定义。可能是什么原因?

// remove stupid MSVC min/max macro definitions
#ifdef WIN32
   #undef min
   #undef max
#endif

1 个答案:

答案 0 :(得分:8)

某些MSVC标头具有预处理器宏来定义minmax。这很糟糕,原因很多。首先,它们不是保留名称,第二,标准库函数具有相同的名称。

MSVC或其他任何通过将minmax定义为宏来破坏规则和代码的方法,使用undef解决了这个问题。

请参阅this related question,其中显示了定义如何破坏代码。