CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Why doesn't this code compile?

  1. #1
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,593

    Why doesn't this code compile?

    Not my code and I haven't used templates much. These two lines

    template <class U>
    static yes_type test(U&, decltype(U(source<U>()))* = 0);

    give the error
    Error C2760 syntax error: unexpected token ')', expected 'expression'

    Thanks.

  2. #2
    Arjay's Avatar
    Arjay is online now Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,315

    Re: Why doesn't this code compile?

    Is the = 0 a comparison operation? If so, should it be == 0 ?

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,593

    Re: Why doesn't this code compile?

    Quote Originally Posted by Arjay View Post
    Is the = 0 a comparison operation? If so, should it be == 0 ?
    I really don't know what it's supposed to be doing, but changing it to == gave me way more errors. That line makes no sense to me, but as I said, I really haven't used templates, so I don't even know how to approach it.

  4. #4
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,189

    Re: Why doesn't this code compile?

    Code:
    template <class U>
    static yes_type test(U&, decltype(U(source<U>()))* = 0);
    This looks like a function declaration with name test. The first parameter is U& and the second is an optional decltype(U(source<U>()))* which defaults to 0 (should be nullptr as that parameter is a pointer) if not present. decltype() returns the type of its argument without evaluating it. At compile time, U is replaced with the actual type used when the function test() is called.

    This compiles OK with VS2019 as C++17 if yes_type type is defined.

    The function definition will look something like:

    Code:
    template <class U>
    yes_type test(U& param1, decltype(U(source<U>()))* param2)
    {
    ...
    }
    How is it being used?
    Last edited by 2kaud; June 17th, 2020 at 10:19 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++17 Compiler: Microsoft VS2019 (16.7.0)

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,593

    Re: Why doesn't this code compile?

    Thanks. I don't know how it's being used. It seems to be a boost file. It's a large project I need to make a small change to. I'm going to have to wait till the guy that wrote it comes back from vacation.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)