#Unscoped enums making a scope

18 messages · Page 1 of 1 (latest)

amber ivy
#

This whole time I used unscoped enum values without a scope but I just realized that you can also access it through a scope. How exactly does this work? I know that in C the enum values just get injected to its surrounding scope so when I saw fha unscoped enums were just basically C enums I’m confused Why can it be accessed through a scope and just by itself ie.

enum MyEnum{
  VALUE
};

MyEnum x = VALUE; //works
MyEnum y = MyEnum::VALUE; //works
native lynxBOT
#

When your question is answered use !solved or the button below to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

bleak ivy
paper prawn
#

would ::VALUE also work ? thinkeyes

bleak ivy
#

that's just how they decided to design it to keep compatible with C but still make use of namespacing

bleak ivy
amber ivy
devout arch
#

C didn't have namespacing

amber ivy
#

Then why does it have a scope resolution or whatever it’s called lol

#

So it does it like c and cpp

paper prawn
amber ivy
#

In c since there are no namespaces if you do enum in the global namespace, the values are in the global scope. Ie, if you nest an enum in a struct, it doesn’t make a scope so it goes into the global scope.

#

I think that’s how it works??? I may or may not know what I’m saying

#

lol

bleak ivy
bleak ivy