A simple question about Enum
-
- 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
The first one creates an unnamed
enum
type, and defines the constants
to have the value 20. I don't know if theconst
has any effect there sinceenum
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 werestatic const int s=20;
then it declares aint
variable calleds
, 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: -
The first one creates an unnamed
enum
type, and defines the constants
to have the value 20. I don't know if theconst
has any effect there sinceenum
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 werestatic const int s=20;
then it declares aint
variable calleds
, 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: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
-
The first one creates an unnamed
enum
type, and defines the constants
to have the value 20. I don't know if theconst
has any effect there sinceenum
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 werestatic const int s=20;
then it declares aint
variable calleds
, 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: