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;








6















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.










share|improve this question






















  • 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


















6















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.










share|improve this question






















  • 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














6












6








6








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.










share|improve this question














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++






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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













3 Answers
3






active

oldest

votes


















12














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; 





share|improve this answer
































    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; 





    share|improve this answer






























      2














      return 1 : 2; is a syntax error, it is not valid code.



      A correct statement would be more like return (y) ? 1 : 2; instead.






      share|improve this answer























        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
        );



        );













        draft saved

        draft discarded


















        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









        12














        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; 





        share|improve this answer





























          12














          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; 





          share|improve this answer



























            12












            12








            12







            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; 





            share|improve this answer















            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; 






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 33 mins ago

























            answered 1 hour ago









            S.M.S.M.

            6,47241830




            6,47241830























                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; 





                share|improve this answer



























                  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; 





                  share|improve this answer

























                    2












                    2








                    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; 





                    share|improve this answer













                    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; 






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 1 hour ago









                    Jerry CoffinJerry Coffin

                    391k52476924




                    391k52476924





















                        2














                        return 1 : 2; is a syntax error, it is not valid code.



                        A correct statement would be more like return (y) ? 1 : 2; instead.






                        share|improve this answer



























                          2














                          return 1 : 2; is a syntax error, it is not valid code.



                          A correct statement would be more like return (y) ? 1 : 2; instead.






                          share|improve this answer

























                            2












                            2








                            2







                            return 1 : 2; is a syntax error, it is not valid code.



                            A correct statement would be more like return (y) ? 1 : 2; instead.






                            share|improve this answer













                            return 1 : 2; is a syntax error, it is not valid code.



                            A correct statement would be more like return (y) ? 1 : 2; instead.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 1 hour ago









                            Remy LebeauRemy Lebeau

                            346k19273467




                            346k19273467



























                                draft saved

                                draft discarded
















































                                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.




                                draft saved


                                draft discarded














                                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





















































                                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







                                Popular posts from this blog

                                Log på Navigationsmenu

                                Creating second map without labels using QGIS?How to lock map labels for inset map in Print Composer?How to Force the Showing of Labels of a Vector File in QGISQGIS Valmiera, Labels only show for part of polygonsRemoving duplicate point labels in QGISLabeling every feature using QGIS?Show labels for point features outside map canvasAbbreviate Road Labels in QGIS only when requiredExporting map from composer in QGIS - text labels have moved in output?How to make sure labels in qgis turn up in layout map?Writing label expression with ArcMap and If then Statement?

                                Nuuk Indholdsfortegnelse Etyomologi | Historie | Geografi | Transport og infrastruktur | Politik og administration | Uddannelsesinstitutioner | Kultur | Venskabsbyer | Noter | Eksterne henvisninger | Se også | Navigationsmenuwww.sermersooq.gl64°10′N 51°45′V / 64.167°N 51.750°V / 64.167; -51.75064°10′N 51°45′V / 64.167°N 51.750°V / 64.167; -51.750DMI - KlimanormalerSalmonsen, s. 850Grønlands Naturinstitut undersøger rensdyr i Akia og Maniitsoq foråret 2008Grønlands NaturinstitutNy vej til Qinngorput indviet i dagAntallet af biler i Nuuk må begrænsesNy taxacentral mødt med demonstrationKøreplan. Rute 1, 2 og 3SnescootersporNuukNord er for storSkoler i Kommuneqarfik SermersooqAtuarfik Samuel KleinschmidtKangillinguit AtuarfiatNuussuup AtuarfiaNuuk Internationale FriskoleIlinniarfissuaq, Grønlands SeminariumLedelseÅrsberetning for 2008Kunst og arkitekturÅrsberetning for 2008Julie om naturenNuuk KunstmuseumSilamiutGrønlands Nationalmuseum og ArkivStatistisk ÅrbogGrønlands LandsbibliotekStore koncerter på stribeVandhund nummer 1.000.000Kommuneqarfik Sermersooq – MalikForsidenVenskabsbyerLyngby-Taarbæk i GrønlandArctic Business NetworkWinter Cities 2008 i NuukDagligt opdaterede satellitbilleder fra NuukområdetKommuneqarfik Sermersooqs hjemmesideTurist i NuukGrønlands Statistiks databankGrønlands Hjemmestyres valgresultaterrrWorldCat124325457671310-5