What does this colon mean? It is not labeling, it is not ternary operatorWhat does the explicit keyword mean?What does the C++ standard state the size of int, long type to be?What is the “-->” operator in C++?C++, What does the colon after a constructor mean?What does int argc, char *argv[] mean?What is the meaning of prepended double colon “::”?What are the basic rules and idioms for operator overloading?What does “dereferencing” a pointer mean?What does T&& (double ampersand) mean in C++11?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?
Returning the outputs of a nested structure
What actually is the vector of angular momentum?
Sed Usage to update GRUB file
What happens to matryoshka Mordenkainen's Magnificent Mansions?
Besides the up and down quark, what other quarks are present in daily matter around us?
For a benzene shown in a skeletal structure, what does a substituent to the center of the ring mean?
Father and Son and Grandsons
What is the unit of the area when geometry attributes are calculated in QGIS?
Comment rendre "naysayers" ?
Should my Json storage handle exceptions?
SQL Server Management Studio SSMS 18.0 General Availability release (GA) install fails
Moving the subject of the sentence into a dangling participle
Is one octave above tonic also considered as tonic?
Was Unix ever a single-user OS?
Is there a legal ground for stripping the UK of its UN Veto if Scotland and/or N.Ireland split from the UK?
How to 'Let Go' in Meditation?
Airbnb - host wants to reduce rooms, can we get refund?
Catholic vs Protestant Support for Nazism in Germany
How to reply this mail from potential PhD professor?
When and why did journal article titles become descriptive, rather than creatively allusive?
What is the most remote airport from the center of the city it supposedly serves?
How can I support myself financially as a 17 year old with a loan?
How can I close a gap between my fence and my neighbor's that's on his side of the property line?
Was there ever a Kickstart that took advantage of 68020+ instructions that would work on an A2000?
What does this colon mean? It is not labeling, it is not ternary operator
What does the explicit keyword mean?What does the C++ standard state the size of int, long type to be?What is the “-->” operator in C++?C++, What does the colon after a constructor mean?What does int argc, char *argv[] mean?What is the meaning of prepended double colon “::”?What are the basic rules and idioms for operator overloading?What does “dereferencing” a pointer mean?What does T&& (double ampersand) mean in C++11?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I don't understand one particular use of a semicolon.
I found it in the book "The C++ programming language" by Bjarne Stroustrup, 4th edition, section 11.4.4, page 297:
void g(double y)
[&] f(y); // return type is void
auto z1 = [=](int x) return x+y; // return type is double
auto z2 = [=,y] if (y) return 1; else return 2; // error : body too complicated
// for retur n type deduction
auto z3 =[y]() return 1 : 2; // (Me: HERE!!!) return type is int
auto z4 = [=,y]()−>int if (y) return 1; else return 2; // OK: explicit return type
All comments from Stroustrup, except the one inside the parentheses.
I have no idea what it could be.
It seems like a conditional ternary operator without the first member (and without the "?"), but in that case I don't understand how it could work without a condition.
c++
add a comment |
I don't understand one particular use of a semicolon.
I found it in the book "The C++ programming language" by Bjarne Stroustrup, 4th edition, section 11.4.4, page 297:
void g(double y)
[&] f(y); // return type is void
auto z1 = [=](int x) return x+y; // return type is double
auto z2 = [=,y] if (y) return 1; else return 2; // error : body too complicated
// for retur n type deduction
auto z3 =[y]() return 1 : 2; // (Me: HERE!!!) return type is int
auto z4 = [=,y]()−>int if (y) return 1; else return 2; // OK: explicit return type
All comments from Stroustrup, except the one inside the parentheses.
I have no idea what it could be.
It seems like a conditional ternary operator without the first member (and without the "?"), but in that case I don't understand how it could work without a condition.
c++
It's a compile error on my end (gcc and clang). Plus all those lines need semicolons, but still an error.
– Cruz Jean
1 hour ago
add a comment |
I don't understand one particular use of a semicolon.
I found it in the book "The C++ programming language" by Bjarne Stroustrup, 4th edition, section 11.4.4, page 297:
void g(double y)
[&] f(y); // return type is void
auto z1 = [=](int x) return x+y; // return type is double
auto z2 = [=,y] if (y) return 1; else return 2; // error : body too complicated
// for retur n type deduction
auto z3 =[y]() return 1 : 2; // (Me: HERE!!!) return type is int
auto z4 = [=,y]()−>int if (y) return 1; else return 2; // OK: explicit return type
All comments from Stroustrup, except the one inside the parentheses.
I have no idea what it could be.
It seems like a conditional ternary operator without the first member (and without the "?"), but in that case I don't understand how it could work without a condition.
c++
I don't understand one particular use of a semicolon.
I found it in the book "The C++ programming language" by Bjarne Stroustrup, 4th edition, section 11.4.4, page 297:
void g(double y)
[&] f(y); // return type is void
auto z1 = [=](int x) return x+y; // return type is double
auto z2 = [=,y] if (y) return 1; else return 2; // error : body too complicated
// for retur n type deduction
auto z3 =[y]() return 1 : 2; // (Me: HERE!!!) return type is int
auto z4 = [=,y]()−>int if (y) return 1; else return 2; // OK: explicit return type
All comments from Stroustrup, except the one inside the parentheses.
I have no idea what it could be.
It seems like a conditional ternary operator without the first member (and without the "?"), but in that case I don't understand how it could work without a condition.
c++
c++
asked 1 hour ago
PiockñecPiockñec
363
363
It's a compile error on my end (gcc and clang). Plus all those lines need semicolons, but still an error.
– Cruz Jean
1 hour ago
add a comment |
It's a compile error on my end (gcc and clang). Plus all those lines need semicolons, but still an error.
– Cruz Jean
1 hour ago
It's a compile error on my end (gcc and clang). Plus all those lines need semicolons, but still an error.
– Cruz Jean
1 hour ago
It's a compile error on my end (gcc and clang). Plus all those lines need semicolons, but still an error.
– Cruz Jean
1 hour ago
add a comment |
3 Answers
3
active
oldest
votes
It's a typo. Look at Errata for 2nd and 3rd printings of The C++ Programming Language. The example must be like below:
auto z3 =[y]() return (y) ? 1 : 2;
add a comment |
Looks to me like a simple typo. Should probably be:
auto z3 =[y]() return y ? 1 : 2;
Note that since the lambda doesn't take any parameters, the parens are optional. You could use this instead, if you preferred:
auto z3 =[y] return y ? 1 : 2;
add a comment |
return 1 : 2;
is a syntax error, it is not valid code.
A correct statement would be more like return (y) ? 1 : 2;
instead.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55929336%2fwhat-does-this-colon-mean-it-is-not-labeling-it-is-not-ternary-operator%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's a typo. Look at Errata for 2nd and 3rd printings of The C++ Programming Language. The example must be like below:
auto z3 =[y]() return (y) ? 1 : 2;
add a comment |
It's a typo. Look at Errata for 2nd and 3rd printings of The C++ Programming Language. The example must be like below:
auto z3 =[y]() return (y) ? 1 : 2;
add a comment |
It's a typo. Look at Errata for 2nd and 3rd printings of The C++ Programming Language. The example must be like below:
auto z3 =[y]() return (y) ? 1 : 2;
It's a typo. Look at Errata for 2nd and 3rd printings of The C++ Programming Language. The example must be like below:
auto z3 =[y]() return (y) ? 1 : 2;
edited 33 mins ago
answered 1 hour ago
S.M.S.M.
6,47241830
6,47241830
add a comment |
add a comment |
Looks to me like a simple typo. Should probably be:
auto z3 =[y]() return y ? 1 : 2;
Note that since the lambda doesn't take any parameters, the parens are optional. You could use this instead, if you preferred:
auto z3 =[y] return y ? 1 : 2;
add a comment |
Looks to me like a simple typo. Should probably be:
auto z3 =[y]() return y ? 1 : 2;
Note that since the lambda doesn't take any parameters, the parens are optional. You could use this instead, if you preferred:
auto z3 =[y] return y ? 1 : 2;
add a comment |
Looks to me like a simple typo. Should probably be:
auto z3 =[y]() return y ? 1 : 2;
Note that since the lambda doesn't take any parameters, the parens are optional. You could use this instead, if you preferred:
auto z3 =[y] return y ? 1 : 2;
Looks to me like a simple typo. Should probably be:
auto z3 =[y]() return y ? 1 : 2;
Note that since the lambda doesn't take any parameters, the parens are optional. You could use this instead, if you preferred:
auto z3 =[y] return y ? 1 : 2;
answered 1 hour ago
Jerry CoffinJerry Coffin
391k52476924
391k52476924
add a comment |
add a comment |
return 1 : 2;
is a syntax error, it is not valid code.
A correct statement would be more like return (y) ? 1 : 2;
instead.
add a comment |
return 1 : 2;
is a syntax error, it is not valid code.
A correct statement would be more like return (y) ? 1 : 2;
instead.
add a comment |
return 1 : 2;
is a syntax error, it is not valid code.
A correct statement would be more like return (y) ? 1 : 2;
instead.
return 1 : 2;
is a syntax error, it is not valid code.
A correct statement would be more like return (y) ? 1 : 2;
instead.
answered 1 hour ago
Remy LebeauRemy Lebeau
346k19273467
346k19273467
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55929336%2fwhat-does-this-colon-mean-it-is-not-labeling-it-is-not-ternary-operator%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It's a compile error on my end (gcc and clang). Plus all those lines need semicolons, but still an error.
– Cruz Jean
1 hour ago