在源代码中,我看到min和max未定义。可能是什么原因?
// remove stupid MSVC min/max macro definitions
#ifdef WIN32
#undef min
#undef max
#endif
答案 0 :(得分:8)
某些MSVC标头具有预处理器宏来定义min
和max
。这很糟糕,原因很多。首先,它们不是保留名称,第二,标准库函数具有相同的名称。
MSVC或其他任何通过将min
和max
定义为宏来破坏规则和代码的方法,使用undef
解决了这个问题。
请参阅this related question,其中显示了定义如何破坏代码。