std :: max - 期望一个标识符 [英] std::max - expected an identifier

查看:478
本文介绍了std :: max - 期望一个标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 std :: max 的问题。我不能想出来。

  int border = 35; 
int myInt = 2;
int myOtherInt = 3;
int z = std :: max(myInt + 2 * border,myOtherInt + 2 * border);

我已包含算法标准标题。当我鼠标超过max时,我得到:


错误:需要一个标识符


编译错误:


错误C2589:' '::'右侧的非法令牌

错误C2059:语法错误: '::'


有什么问题?

解决方案

危害猜测,因为你使用VC ++–把这个放在任何 #include s:

  #define NOMINMAX 

windows.h 定义名为 min max 例如:

  #define min(a,b)(((a)<(b))? :(b))
#define max(a,b)(((a)>(b))?(a):(b))
pre>

Windows SDK包含了这些宏,因为C ++标准化之前,但是因为它们明显对C ++标准库造成破坏,所以可以定义



通常,如果您使用C ++(而不是C),并且包括 windows.h 始终首先定义 NOMINMAX


I'm having a problem with std::max. I can't figure it out.

int border = 35;
int myInt = 2;
int myOtherInt = 3;
int z = std::max(myInt + 2 * border, myOtherInt + 2 * border);

I've included the algorithm standard header. When I mouse over max, I am getting:

Error: expected an identifier

And a compile errors of:

error C2589: '(' : illegal token on right side of '::'
error C2059: syntax error : '::'

What is wrong?

解决方案

Hazarding a guess, since you're using VC++ – put this before any #includes:

#define NOMINMAX

windows.h defines macros named min and max like so:

#define min(a,b)            (((a) < (b)) ? (a) : (b))
#define max(a,b)            (((a) > (b)) ? (a) : (b))

The Windows SDK has contained these macros since before C++ was standardized, but because they obviously play havoc with the C++ standard library, one can define the NOMINMAX macro to prevent them from being defined.

As a rule, if you're using C++ (as opposed to C) and including windows.h, always define NOMINMAX first.

这篇关于std :: max - 期望一个标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆