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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. member array initialization

member array initialization

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestion
8 Posts 4 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.
  • N Offline
    N Offline
    Naveen
    wrote on last edited by
    #1

    Hi, Can I initialize a member array of a class from the constructor class test { int Myarray[10]; test() { } }; here I want to set the value of all elements in Myarray as 0. Is there any way to do it with out using memset()...? nave

    A 1 Reply Last reply
    0
    • N Naveen

      Hi, Can I initialize a member array of a class from the constructor class test { int Myarray[10]; test() { } }; here I want to set the value of all elements in Myarray as 0. Is there any way to do it with out using memset()...? nave

      A Offline
      A Offline
      ajmalsiddiqi
      wrote on last edited by
      #2

      dear why do You not use loop to initialize array with ur desired value. ajmalsiddiqui -- modified at 6:50 Monday 8th May, 2006

      N 1 Reply Last reply
      0
      • A ajmalsiddiqi

        dear why do You not use loop to initialize array with ur desired value. ajmalsiddiqui -- modified at 6:50 Monday 8th May, 2006

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #3

        in normal case int MyArray[10] = {0}; will initialize all the elements in that array..I just want to know is this possible in the class memebers( using initialization list ) nave

        N 1 Reply Last reply
        0
        • N Naveen

          in normal case int MyArray[10] = {0}; will initialize all the elements in that array..I just want to know is this possible in the class memebers( using initialization list ) nave

          N Offline
          N Offline
          Nibu babu thomas
          wrote on last edited by
          #4

          Naveen R wrote:

          using initialization list

          Initialization list can only be specified when an array is being declared.


          Nibu thomas Software Developer Faqs by Michael dunn

          N 1 Reply Last reply
          0
          • N Nibu babu thomas

            Naveen R wrote:

            using initialization list

            Initialization list can only be specified when an array is being declared.


            Nibu thomas Software Developer Faqs by Michael dunn

            N Offline
            N Offline
            Naveen
            wrote on last edited by
            #5

            I didn't understand? can u plz explain? nave

            J 1 Reply Last reply
            0
            • N Naveen

              I didn't understand? can u plz explain? nave

              J Offline
              J Offline
              jhwurmbach
              wrote on last edited by
              #6

              Initializer lists are used in a constructor to initialize members of that class. Not local variables defined inside a class.


              "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

              N 1 Reply Last reply
              0
              • J jhwurmbach

                Initializer lists are used in a constructor to initialize members of that class. Not local variables defined inside a class.


                "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

                N Offline
                N Offline
                Naveen
                wrote on last edited by
                #7

                Ya that I know ..I tried/want to initialize a member variable not a local variable inside a function( here MyArray is a member variable ) see the class delcaration.. http://www.codeproject.com/script/comments/forums.asp?msg=1478001&forumid=1647#xx1478001xx[^] nave

                J 1 Reply Last reply
                0
                • N Naveen

                  Ya that I know ..I tried/want to initialize a member variable not a local variable inside a function( here MyArray is a member variable ) see the class delcaration.. http://www.codeproject.com/script/comments/forums.asp?msg=1478001&forumid=1647#xx1478001xx[^] nave

                  J Offline
                  J Offline
                  jhwurmbach
                  wrote on last edited by
                  #8

                  No, I don't think you can ust initializer lists with plain old C-Arrays. You are bound to use a loop or memset.


                  "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

                  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