我有以下模板声明:
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 上进行编译。知道问题是什么吗?
Edit:使用 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 号线,就是前面提到的那条线。
我的猜测是max
已经做了宏。这发生在内部的某个时刻windows.h
.
Define NOMINMAX
在包括停止之前windows.h
这样做。
EDIT:
我仍然相信这是你的问题。 (不包括<limits>
会导致不同的错误)。地方#undef max
and #undef min
就在函数之前,然后重试。如果这解决了问题,我是对的,你的NOMINMAX
没有被正确定义。 (将其添加为项目设置。)
您还可以通过以下方式防止宏扩展:(std::numeric_limits<T>::max)()
.
顺便说一句,为什么不这样做std::numeric_limits<T>::min()
而不是否定最大值?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)