1: #include <windows.h>
2: int& max(int& a, int& b)
3: {
4: return a > b ? a : b;
5: }
6: int main()
7: {
8: return 0;
9: }Visual Studio 2008速成版大声疾呼:
1>e:...\main.cpp(2):错误C2062:类型'int‘意外
1>e:...\main.cpp(2):错误C2062:类型'int‘意外
1>e:...\main.cpp(2):错误C2059:语法错误:')‘
1>e:...\main.cpp(3):错误C2143:语法错误:'{‘前缺少';’
1>e:...\main.cpp(3):错误C2447:'{‘:缺少函数头(旧式正式列表?)
如果我用stdio.h或iostream替换windows.h (或者如果我删除它),它似乎可以工作。
为什么会这样呢?
发布于 2013-04-22 00:20:25
#include <windows.h>
#undef min
#undef max
int & max(int& a, int& b)
{
return a > b ? a : b;
}
int main()
{
return 0;
}<windows.h>为max和min定义了宏,这会干扰您的操作。
其他方式
NOMINMAX。这是推荐使用一些STL标头的常见解决方案,这些标头定义了min和max。#define NOMINMAX #include
https://stackoverflow.com/questions/16133265
复制相似问题