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

  • SEARCH
  • Home
  • 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 963297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:39:00+00:00 2026-05-16T01:39:00+00:00

template <typename T> void function(T arg1, T min = std::numeric_limits<T>::min(), T max = std::numeric_limits<T>::max())

  • 0
template <typename T> void function(T arg1, 
    T min = std::numeric_limits<T>::min(),
    T max = std::numeric_limits<T>::max())
{
}

template <> void function<int>(int arg1, int min,int max)
{
}

int main(int argc,char* argv[])
{
    function<int>(1);
}

it give syntax error C2689 and C2059 on function default argument line on :: token.
but without specialization, it doing fine. and if I change default argument
and still doing specialization:

template <typename T> void function(T arg1, 
    T min = T(0),
    T max = T(1))
{
}
template <> void function<int>(int arg1, int min,int max)
{
}

the problem gone too.

now if I use it like this: function<int>(1,2,3); or function<float>(1.0f) its fine, so it seems that if template function is specialized, we must rewrite the default argument when call it?

but on my second case, where i replace std::numeric_limits<T>::.. with T(..) there no syntax error when calling function<int>(1), why is that?

(I’am using Visual Studio 2010 x64)

as original problem is because of bug, the question now changed to how to workaround it?

  • 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-05-16T01:39:00+00:00Added an answer on May 16, 2026 at 1:39 am

    There is nothing wrong with the code; Comeau Online, Intel C++ 11.1, and g++ 4.1.2 compile it successfully.

    I would guess that it is a bug in the compiler. I recently submitted a related, but slightly different bug report against the Visual C++ 2010 compiler.


    As a workaround, you can wrap the calls:

    template <typename T>
    T get_limits_min() { return std::numeric_limits<T>::min(); }
    
    template <typename T>
    T get_limits_max() { return std::numeric_limits<T>::max(); }
    
    template <typename T> void function(T arg1, 
        T min = get_limits_min<T>(),
        T max = get_limits_max<T>())
    {
    }
    

    Ugly? Quite.


    I posted the following in response to the bug you reported on Microsoft Connect:

    The primary template must have a parameter that has a default argument value. The default argument value must be a member function of a class template not in the global namespace.

    The following is minimal code to reproduce:

    namespace N
    {
        template <typename T>
        struct S
        {
            static T g() { return T(); }
        };
    }
    
    template <typename T> void f(T = N::S<T>::g()) { }
    
    template <> void f<>(int) { }
    
    int main()
    {
        f<int>();
    }
    

    The compiler emits the following errors, both on the line where the primary template is defined:

    error C2589: '::' : illegal token on right side of '::'
    error C2059: syntax error : '::'
    

    Interestingly, there is another issue if the class template is in the global namespace. Given the following code:

    template <typename T>
    struct S
    {
        static T g() { return T(); }
    };
    
    template <typename T> void f(T = ::S<T>::g()) { }
    
    template <> void f<>(int) { }
    
    int main()
    {
        f<int>();
    }
    

    The compiler emits the following error on the line on which the primary template is defined:

    error C2064: term does not evaluate to a function taking 0 arguments
    

    Both of these example test cases are well-formed C++ programs.

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

Sidebar

Ask A Question

Stats

  • Questions 495k
  • Answers 495k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is no standard location for application logs. Use what… May 16, 2026 at 11:13 am
  • Editorial Team
    Editorial Team added an answer I found this to be a good solution $("#myDialogID").dialog({ closeOnEscape:… May 16, 2026 at 11:13 am
  • Editorial Team
    Editorial Team added an answer All that complicated code in JavaScript appears to just try… May 16, 2026 at 11:13 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to create a function: template <typename T> void doIt( T*& p )
I have the following template function which prints to cout: template <typename T> void
In the code below: template<typename T> struct X {}; int main() { X<int()> x;
template<typename Functor, typename Return, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5,
If I have a function template with typename T , where the compiler can
Given the following template: template <typename T> class wrapper : public T {}; What
My question is related to this question. #include<iostream> template< typename T > class T1
Using GCC 4.2. I have this metatemplate for conditional type: template <bool condition, typename
I'm currently working on cleaning up an API full of function templates, and had
I want to be able to templatize a class on a member function without

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.