CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    [RESOLVED] Namespace problem with older version of MSVC

    I have a project here which still needs to build with VS2008 and I've discovered a problem with std::min() and std::max()

    Code:
    #include <algorithm>
    
    int n = std::min(2, 1);
    The compiler gives me:- error C2589: '(' : illegal token on right side of '::'

    std::max() gives the same error but int n = min(2, 1); compiles okay. I'm guessing it's using the wrong versions of min() and max() somehow, although I'm pretty sure std::min() and std::max() were supported back then. Can anyone remember/suggest what the solution was?
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #2
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: Namespace problem with older version of MSVC

    Apologies - I just realised this was solved back in 2013
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: [RESOLVED] Namespace problem with older version of MSVC

    Another way is to specify the type for the template- again so that the **** pre-compiler won't confuse with a macro!

    Code:
    std::min<int>(1, 2);
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: [RESOLVED] Namespace problem with older version of MSVC

    That also worked 2kaud - many thanks !
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: [RESOLVED] Namespace problem with older version of MSVC

    That 'trick' is also useful if the arguments are of different types:

    Code:
    std::min(1, 2U);
    won't compile as the 1st arg is int, the second is unsigned int - so template type deduction reports an error. Whereas:

    Code:
    std::min<int>(1, 2U);
    does compile as the type is forced to an int for both arguments.
    Last edited by 2kaud; June 19th, 2020 at 02:30 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured