-
June 16th, 2020, 01:23 PM
#1
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.
-
June 16th, 2020, 03:02 PM
#2
Re: Why doesn't this code compile?
Is the = 0 a comparison operation? If so, should it be == 0 ?
-
June 16th, 2020, 03:27 PM
#3
Re: Why doesn't this code compile?
Originally Posted by Arjay
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.
-
June 17th, 2020, 06:03 AM
#4
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++23 Compiler: Microsoft VS2022 (17.6.5)
-
June 17th, 2020, 09:32 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|