Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal token on right side of ::

Tags:

c++

linux

winapi

I have the following template declaration:

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; 

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?

Edit: 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 

Line 216, is the line previously mentioned.

like image 929
Adam Haile Avatar asked Apr 01 '10 15:04

Adam Haile


2 Answers

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

Define NOMINMAX prior to including to stop windows.h from doing that.

EDIT:

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.)

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


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

like image 141
GManNickG Avatar answered Oct 11 '22 22:10

GManNickG


Looks like you need to:

#include <limits>

like image 24
John Dibling Avatar answered Oct 12 '22 00:10

John Dibling