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. A simple question about Enum

A simple question about Enum

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
4 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.
  • M Offline
    M Offline
    Maer727
    wrote on last edited by
    #1

    - What is the difference between the following two sentences? - const static enum { s = 20 }; - const static s = 20; - Can you show me an example? - Regards, Maer

    M 1 Reply Last reply
    0
    • M Maer727

      - What is the difference between the following two sentences? - const static enum { s = 20 }; - const static s = 20; - Can you show me an example? - Regards, Maer

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      The first one creates an unnamed enum type, and defines the constant s to have the value 20. I don't know if the const has any effect there since enum values are by definition constants. The second is a syntax error. It's almost a variable declaration - it's just missing the type. If it were static const int s=20; then it declares a int variable called s, with value 20 that can't be changed (const) and is visible only in that .CPP file (static). --Mike-- http://home.inreach.com/mdunn/ #include "witty_sig.h" :love: your :bob: with :vegemite: and :beer:

      A M 2 Replies Last reply
      0
      • M Michael Dunn

        The first one creates an unnamed enum type, and defines the constant s to have the value 20. I don't know if the const has any effect there since enum values are by definition constants. The second is a syntax error. It's almost a variable declaration - it's just missing the type. If it were static const int s=20; then it declares a int variable called s, with value 20 that can't be changed (const) and is visible only in that .CPP file (static). --Mike-- http://home.inreach.com/mdunn/ #include "witty_sig.h" :love: your :bob: with :vegemite: and :beer:

        A Offline
        A Offline
        Alvaro Mendez
        wrote on last edited by
        #3

        Mike, The second case is technically not a syntax error since the compiler assumes the default "int" type for the variable. Still, it's bad form and should not be used. Regards, Alvaro

        1 Reply Last reply
        0
        • M Michael Dunn

          The first one creates an unnamed enum type, and defines the constant s to have the value 20. I don't know if the const has any effect there since enum values are by definition constants. The second is a syntax error. It's almost a variable declaration - it's just missing the type. If it were static const int s=20; then it declares a int variable called s, with value 20 that can't be changed (const) and is visible only in that .CPP file (static). --Mike-- http://home.inreach.com/mdunn/ #include "witty_sig.h" :love: your :bob: with :vegemite: and :beer:

          M Offline
          M Offline
          Maer727
          wrote on last edited by
          #4

          - Thanks, Mike pal! - I still have a question. What means "by definition constants" in your reply? - Can you show me an example? - Regards, Maer

          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