警告C4003和错误C2589和C2059 on:x = std :: numeric_limits< int> :: max(); [英] warning C4003 and errors C2589 and C2059 on: x = std::numeric_limits<int>::max();
问题描述
这行在小测试程序中正常工作,但在我想要的程序中,我得到以下编译器投诉:
#include< limits>
x = std :: numeric_limits< int> :: max();
c:\ ... \x.cpp(192):warning C4003:宏'max'的实际参数不足
c:\ ... \x.cpp (192):错误C2589:'(':'::'的右边的非法令牌
c:\ ... \x.cpp(192):错误C2059:语法错误:'::'
我得到相同的结果:
#include< limits>
using namespace std;
x = numeric_limits< int> :: max();
$为什么它看到max作为宏的最大值(a,b);?
<当包含定义 min
或 max $ c的Windows标题时,通常会出现这种情况$ c> macro如果你使用Windows头文件,在代码中放置 #define NOMINMAX
,或者使用等效的编译器开关构建(例如使用 / DNOMINMAX for Visual Studio)。
请注意,使用 NOMINMAX
构建将禁止在整个程序中使用宏。如果需要使用 min
或 max
操作,请使用 std :: min )
头中的 或 std :: max()
/ p>
This line works correctly in a small test program, but in the program for which I want it, I get the following compiler complaints:
#include <limits>
x = std::numeric_limits<int>::max();
c:\...\x.cpp(192) : warning C4003: not enough actual parameters for macro 'max'
c:\...\x.cpp(192) : error C2589: '(' : illegal token on right side of '::'
c:\...\x.cpp(192) : error C2059: syntax error : '::'
I get the same results with:
#include <limits>
using namespace std;
x = numeric_limits<int>::max();
Why is it seeing max as the macro max(a,b); ?
解决方案 This commonly occurs when including a Windows header that defines a min
or max
macro. If you're using Windows headers, put #define NOMINMAX
in your code, or build with the equivalent compiler switch (i.e. use /DNOMINMAX for Visual Studio).
Note that building with NOMINMAX
disables use of the macro in your entire program. If you need to use the min
or max
operations, use std::min()
or std::max()
from the <algorithm>
header.
这篇关于警告C4003和错误C2589和C2059 on:x = std :: numeric_limits< int> :: max();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文