Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7849773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:37:53+00:00 2026-06-02T18:37:53+00:00

In my application (compiled under Visual C++ 2010), I have code like this in

  • 0

In my application (compiled under Visual C++ 2010), I have code like this in a header file:

// example.h
#pragma once

#include <limits>

namespace myspace
{

// A generic equality test
template<typename T> inline bool equal(
    const T &v1, 
    const T &v2, 
    const T &eps = std::numeric_limits<T>::epsilon())
{
    return (v1 == v2);
}

// Template specialization for floating-point numbers
template<> bool equal<float>(
    const float &v1, 
    const float &v2, 
    const float &eps);

// A generic equality test for finite-precision real number representations (with epsilon)
template<typename T> inline bool realEqual(
    const T &p, 
    const T &q, 
    const T &eps = std::numeric_limits<T>::epsilon())
{
    return (fabs(p - q) < eps);
}

} // namespace myspace

…and some code in a .cpp file:

// example.cpp
#include "example.h"

using namespace std;
using namespace myspace;

// equal-macro specialization that calls the appropriate equality test function for real numbers
template<> bool myspace::equal<float>(
    const float &v1, 
    const float &v2, 
    const float &eps)
{
    return (realEqual(v1, v2, eps));
}

int _tmain(int argc, _TCHAR* argv[])
{
    float a,b;
    bool x = realEqual(a,b); // OK
    bool x = equal(a,b); // compile error
    return 0;
}

This fails to compile, giving me:

—— Build started: Project: test, Configuration: Debug Win32 ——
test.cpp
c:\users\ninja\documents\visual studio 2010\projects\test\test\test.h(10): error C2589: ‘::’ : illegal token on right side of ‘::’
c:\users\ninja\documents\visual studio 2010\projects\test\test\test.h(10): error C2059: syntax error : ‘::’
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The offending line is the one with the definition of the “eps” parameter’s default value for the equal() function.

A google search revealed people’ve had similar “illegal token” errors with other functions from numeric_limits, namely min() and max(), but these were due to some #define present in Windows-specific c++ standard library header files, which defined “min” and “max” for some legacy reasons. No mention about epsilon(), and I’m absolutely stumped about why I’m getting an error here. Anyway, changing the function name from “equal” to something like “smartEqual” still gives the same error, so the name is obviously not the issue. What is?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:37:57+00:00Added an answer on June 2, 2026 at 6:37 pm

    It looks like it’s caused by this bug in Visual Studio:

    https://connect.microsoft.com/VisualStudio/feedback/details/583081/

    See also here:

    template function specialization default argument

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a ASP.Net web application running in Visual Studio 2010 that is targeting
Is there a way to execute a .NET application compiled under AnyCPU as a
I have an MFC application compiled with /clr and I'm trying to implement a
How do I tell if my application (compiled in Visual Studio 2008 as Any CPU )
We have a MFC 8 application compiled with /CLR that contains a larger amount
I have a .NET windows forms application compiled as x86 – it needs to
here is a good question: I have an application compiled for iPhone OS 2.21.
New microsoft's IDEs like Visual Studio 2008 or 2010 creates exe files with manifest
I would like to refactor a large legacy application originally written in Visual Basic
We have a very important application, but so far no source code. The application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.