enum

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

I know that if you write
const int TAL = 99;
then TAL is implicitly static

Now I wonder if enum is also static implicitly
if I write
enum number {one ,two, three}
is this enum number implicitly static.


//Tony
 
I know that if you write
const int TAL = 99;
then TAL is implicitly static

Now I wonder if enum is also static implicitly
if I write
enum number {one ,two, three}
is this enum number implicitly static.

Yes. You cannot do

number.one = 5;

(And remember, in your example above, one = 0, two = 1, three = 2!)
 
Hello!

You didn't understand my question. I just wonder if this enum number belong
to the instans or class.
If it's implicitly static it belongs to the class otherwise it belong to the
instansen.

//Tony
 
You didn't understand my question. I just wonder if this enum number
belong to the instans or class.
If it's implicitly static it belongs to the class otherwise it belong to
the instansen.

Okay, then yes, enums are always static given the way you asked the
question. You need to realize that enums are types, just like classes, and
therefore there's really no concept of static or instance when you talk
about them. (Yes, there are "static classes," but it's an extension of the
term "static.")
 
Hello!

You didn't understand my question. I just wonder if this enum number belong
to the instans or class.
If it's implicitly static it belongs to the class otherwise it belong to the
instansen.

I did not understand it neither :)

enum is a type so they are "static" and I mean with " because it's not
a correct thing to say after all, scoped is more accurately.
 
Tony said:
Hello!

You didn't understand my question. I just wonder if this enum number
belong to the instans or class.
If it's implicitly static it belongs to the class otherwise it belong
to the instansen.

The names of the enum alternatives are introduced in the parent type, not
members of each instance. e.g.

struct S { enum E { first, second, third }; } s;

The alternatives are named:

S::first
S::second
S::third

not

s.first
s.second
s.third
 
Back
Top