警告 C4003:宏“max”的实际参数不足 - Visual Studio 2010 C++
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6884093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
warning C4003: not enough actual parameters for macro 'max' - Visual Studio 2010 C++
提问by petersaints
I have the following warnings while compiling an openFrameworks 007 project on Visual Studio 2010 SP1:
在 Visual Studio 2010 SP1 上编译 openFrameworks 007 项目时出现以下警告:
d:\pedro\development\videoflow\openframeworks\libs\openframeworks\types\ofcolor.h(127): warning C4003: not enough actual parameters for macro 'max'
d:\pedro\development\videoflow\openframeworks\libs\openframeworks\types\ofcolor.h(128): warning C4003: not enough actual parameters for macro 'max'
d:\pedro\development\videoflow\openframeworks\libs\openframeworks\graphics\ofpixels.h(150): warning C4003: not enough actual parameters for macro 'max'
d:\pedro\development\videoflow\openframeworks\libs\openframeworks\graphics\ofpixels.h(151): warning C4003: not enough actual parameters for macro 'max'
From what I could tell this warnings are usually followed by errors but in my case everything works ok. The affected code is below:
据我所知,此警告通常伴随着错误,但在我的情况下,一切正常。受影响的代码如下:
const float srcMax = ( (sizeof(SrcType) == sizeof(float) ) ? 1.f : numeric_limits<SrcType>::max() );
const float dstMax = ( (sizeof(PixelType) == sizeof(float) ) ? 1.f : numeric_limits<PixelType>::max() );
I tried to set NOMINMAX on the preprocessor but since openFrameworks also defines NOMINMAX on ofConstants.h I get a bunch of warnings that NOMINMAX is already defined.
我试图在预处理器上设置 NOMINMAX,但由于 openFrameworks 还在 ofConstants.h 上定义了 NOMINMAX,我收到了一堆已经定义 NOMINMAX 的警告。
I have tried to define NOMINMAX on the affected openFrameworks files but it results on the same warning (in fact if I analyze the files included on ofColor.h and ofPixel.h they end up including ofConstants.h so NOMINMAX should be defined).
我试图在受影响的 openFrameworks 文件上定义 NOMINMAX,但结果是相同的警告(实际上,如果我分析 ofColor.h 和 ofPixel.h 中包含的文件,它们最终会包含 ofConstants.h,因此应定义 NOMINMAX)。
Any idea on how to solve this? If you don't... what would be best? This warnings or a bunch of warnings that NOMINMAX is already defined?
关于如何解决这个问题的任何想法?如果你不......什么最好?这个警告还是一堆已经定义了 NOMINMAX 的警告?
EDIT:
编辑:
BTW when I talked about errors I was talking about these: warning C4003 and errors C2589 and C2059 on: x = std::numeric_limits<int>::max();
顺便说一句,当我谈论错误时,我在谈论这些:警告 C4003 以及错误 C2589 和 C2059 上: x = std::numeric_limits<int>::max();
I get this (the warning plus 2 errors) if I try to reproduce the problem on a clean C++ project. But on my openFrameworks project I just get the warnings. That's why I get confused!!
如果我尝试在一个干净的 C++ 项目上重现该问题,我会得到这个(警告加上 2 个错误)。但是在我的 openFrameworks 项目中,我只收到警告。这就是我困惑的原因!!
回答by Hans Passant
You are not the first to be bitten by these ancient macros. They can't remove them, that would break old code. So they came up with another macro to remove the sting. Make it look like this:
你不是第一个被这些古老的宏咬住的人。他们无法删除它们,这会破坏旧代码。所以他们想出了另一个宏来消除刺痛。让它看起来像这样:
#ifndef NOMINMAX
# define NOMINMAX
#endif
#include <windows.h>
// Rest of your #includes here
//...
回答by Seth Carnegie
Add #undef max
to the top of the relevant files.
添加#undef max
到相关文件的顶部。
回答by Alex
#pragma warning (disable: 4003)