::右侧的非法令牌 [英] Illegal token on right side of ::

查看:295
本文介绍了::右侧的非法令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下模板声明:

template <typename T>
   void IterTable(int&                       rIdx,
                  std::vector<double>&       rVarVector,
                  const std::vector<T>&      aTable,
                  const T                    aValue,
                  T              aLowerBound = -(std::numeric_limits<T>::max()), //illegal token on right side of '::' shows here
                  bool                       aLeftOpen = true) const;

在-(std :: numeric_limits ::: max())"的行上引发如上所述的非法令牌错误.我从尝试在Windows上编译的旧Linux源码中获得了此代码.知道是什么问题吗?

Which throws the illegal token error as noted, on the line with "-(std::numeric_limits::max())". I got this code from some old linux source that I'm trying to compile on Windows. Any idea what the issue is?

使用min()也会失败,并且编译器输出为:

It also fails using min(), and the compiler output is:

Error   92  error C2589: '::' : illegal token on right side of '::' c:\projects\r&d\prepaydll\include\cfcdefault.h  216 PrepayDLL

Error   93  error C2059: syntax error : '::'    c:\projects\r&d\prepaydll\include\cfcdefault.h  216 PrepayDLL

第216行是前面提到的行.

Line 216, is the line previously mentioned.

推荐答案

我的猜测是max已成为宏.这发生在windows.h内部的某个点上.

My guess is that max has been made a macro. This happens at some point inside windows.h.

在包括windows.h之前定义NOMINMAX.

我仍然相信这是您的问题. (不包括<limits>会导致不同的错误).将#undef max#undef min放在函数之前,然后重试.如果可以解决,我是正确的,并且您的NOMINMAX定义不正确. (将其添加为项目设置.)

I'm still confident this is your problem. (Not including <limits> would result in a different error). Place #undef max and #undef min just before the function and try again. If that fixes it, I was correct, and your NOMINMAX isn't being defined properly. (Add it as a project setting.)

您还可以通过以下方式阻止宏扩展:(std::numeric_limits<T>::max)().

You can also prevent macro expansion by: (std::numeric_limits<T>::max)().

另一方面,为什么不使用std::numeric_limits<T>::min()而不是最大值?

On a side note, why not do std::numeric_limits<T>::min() instead of negating the max?

这篇关于::右侧的非法令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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