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. array in enum?

array in enum?

Scheduled Pinned Locked Moved C / C++ / MFC
data-structurestutorialquestion
6 Posts 6 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.
  • D Offline
    D Offline
    dkoder
    wrote on last edited by
    #1

    dear All, Just wondered if one knows how to use an array in enum. this would be more convenient then 100 diffreent variables. many thanks, Dominik

    D B 2 Replies Last reply
    0
    • D dkoder

      dear All, Just wondered if one knows how to use an array in enum. this would be more convenient then 100 diffreent variables. many thanks, Dominik

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      I'm not quite sure I understand your question. The enum statement takes the form:

      enum Colors
      {
      Red,
      Blue,
      Green,
      Yellow,
      Brown
      };

      At this point, there are no variables, only one enumerable type.


      "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

      1 Reply Last reply
      0
      • D dkoder

        dear All, Just wondered if one knows how to use an array in enum. this would be more convenient then 100 diffreent variables. many thanks, Dominik

        B Offline
        B Offline
        berndg
        wrote on last edited by
        #3

        As unsure as DavidCrow in what you mean. Assuming you mean an array of enumerated values, then the answer is simple: typedef enum { Blue, Red, Yellow } Color; Color colors[100]; Otherwise... please clarify.

        B 1 Reply Last reply
        0
        • B berndg

          As unsure as DavidCrow in what you mean. Assuming you mean an array of enumerated values, then the answer is simple: typedef enum { Blue, Red, Yellow } Color; Color colors[100]; Otherwise... please clarify.

          B Offline
          B Offline
          BlackDice
          wrote on last edited by
          #4

          I think he needs a struct or class. He's thinking along these lines (I think)

          typedef enum
          {
              Blue,
              Red,
              Yellow,
              int nTypes[9]
          };
          

          I don't think this is possible in an enum My articles www.stillwaterexpress.com BlackDice

          A 1 Reply Last reply
          0
          • B BlackDice

            I think he needs a struct or class. He's thinking along these lines (I think)

            typedef enum
            {
                Blue,
                Red,
                Yellow,
                int nTypes[9]
            };
            

            I don't think this is possible in an enum My articles www.stillwaterexpress.com BlackDice

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            Thanks a lot for your help! Yep, i was after something along these lines: typedef enum { Blue, Red, Yellow, green[9] }; ok, now i know that i need and int in front of green[9]. that helps a lot! will try this tonight!!! many thanks, Dominik

            L 1 Reply Last reply
            0
            • A Anonymous

              Thanks a lot for your help! Yep, i was after something along these lines: typedef enum { Blue, Red, Yellow, green[9] }; ok, now i know that i need and int in front of green[9]. that helps a lot! will try this tonight!!! many thanks, Dominik

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

              ahhh, no, i just see that this is not possile. however, using struct or a class will be a bit unconvenient since it doesn't number the variables automatically. i just like.... typedef enum { Blue, Red, Yellow, Green[9] }; anything else messes up the code i believe, Dominik no one's got an idea???? thanks, Dominik

              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