Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Is this Code Valid?

Is this Code Valid?

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Is this line of code valid in C++:

    int a{1};

    S L 2 Replies Last reply
    0
    • L Lost User

      Is this line of code valid in C++:

      int a{1};

      S Offline
      S Offline
      Shao Voon Wong
      wrote on last edited by
      #2

      Valid in C++11

      L B 2 Replies Last reply
      0
      • S Shao Voon Wong

        Valid in C++11

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Thanks for your reply.

        1 Reply Last reply
        0
        • L Lost User

          Is this line of code valid in C++:

          int a{1};

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Hi, Yes. This is the new direct list initialization available in C++11. Best Wishes, -David Delaune

          L 1 Reply Last reply
          0
          • L Lost User

            Hi, Yes. This is the new direct list initialization available in C++11. Best Wishes, -David Delaune

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Thank you for your reply.

            1 Reply Last reply
            0
            • S Shao Voon Wong

              Valid in C++11

              B Offline
              B Offline
              bkelly13
              wrote on last edited by
              #6

              My searches revealed only a partial answer to int a{1}; What does this do and why might I use it?

              Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

              L 1 Reply Last reply
              0
              • B bkelly13

                My searches revealed only a partial answer to int a{1}; What does this do and why might I use it?

                Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                It merely initialises the variable to the value in braces.

                int i = 1; // and
                int i{1};
                // are the same

                See http://msdn.microsoft.com/en-us/library/w7wd1177.aspx[^].

                B 1 Reply Last reply
                0
                • L Lost User

                  It merely initialises the variable to the value in braces.

                  int i = 1; // and
                  int i{1};
                  // are the same

                  See http://msdn.microsoft.com/en-us/library/w7wd1177.aspx[^].

                  B Offline
                  B Offline
                  bkelly13
                  wrote on last edited by
                  #8

                  I should have included "initialize" in my search. On one hand it really doesn't add anything. On the other, it can standardize initialization methods. An int can be initialized in the same manner as an array. That is of little significance, but often consistency adds more than is immediately apparent. Thanks for taking the time to reply.

                  Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups