::右侧的非法令牌::

时间:2010-04-01 15:06:16

标签: c++ linux winapi

我有以下模板声明:

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())”行上抛出非法令牌错误。我从一些旧的Linux源代码中获得了这个代码,我正在尝试在Windows上编译。知道问题是什么吗?

编辑:使用min()失败,编译器输出为:

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行,是前面提到的那一行。

3 个答案:

答案 0 :(得分:106)

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

在包含停止NOMINMAX之前定义windows.h

编辑:

我仍然相信这是你的问题。 (不包括<limits>会导致不同的错误)。在功能前放置#undef max#undef min,然后重试。如果修复它,我是正确的,并且您的NOMINMAX未正确定义。 (将其添加为项目设置。)

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


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

答案 1 :(得分:1)

看起来你需要:

#include <limits>

答案 2 :(得分:0)

我写了一个“测试工具”,其中包含一个简单的结构,其中包含您的方法声明(以及其他任何内容),以及#included <limits><vector>,并使用{调用(并因此实例化)该方法{1}} T,它在Windows Vista上的Visual Studio 2008 Express和Linux 2.6上的GCC 4.2.4上编译得很好。

我建议尝试只使用其中的“问题”来构建最少量的代码,如果实际上构建了该代码,则在项目的其余部分中重新添加,直到它出现故障,然后您就会知道导致它的原因。