Illegal token on right side of ::

前端 未结 3 957
傲寒
傲寒 2021-01-31 01:25

I have the following template declaration:

template 
   void IterTable(int&                       rIdx,
                  std::vector

        
相关标签:
3条回答
  • 2021-01-31 02:08

    Looks like you need to:

    #include <limits>

    0 讨论(0)
  • 2021-01-31 02:12

    I wrote a "test harness" with a trivial struct containing your method declaration (and nothing else), and #included <limits> and <vector>, and invoked (and thus instantiated) the method with T being int, and it compiled just fine, both on Visual Studio 2008 Express on Windows Vista and with GCC 4.2.4 on Linux 2.6.

    I suggest trying to build only a minimal amount of code with the "problem" in it, and if that actually does build, add back in the rest of your project until it breaks, then you'll know what caused it.

    0 讨论(0)
  • 2021-01-31 02:21

    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?

    0 讨论(0)
提交回复
热议问题