scope of enum

W

wenmang

Hi,
I encountered some legacy codes with multiple definitions for some
symbols in term of enum(global naemspace pollution). How can I enforce
the scope of an enum? e.g.,
enum MyEnum
{
OK
};
enum YourEnum
{
OK=1
};

If I only want my enum value for symbol OK in MyEnum scope, how can I
do it?
 
V

Victor Bazarov

Hi,
I encountered some legacy codes with multiple definitions for some
symbols in term of enum(global naemspace pollution). How can I enforce
the scope of an enum? e.g.,
enum MyEnum
{
OK
};
enum YourEnum
{
OK=1
};

If I only want my enum value for symbol OK in MyEnum scope, how can I
do it?

Wrap it in a namespace or a struct, and refer to it using that name:

struct MyEnum {
enum type { OK };
};

...
MyEnum::type var = MyEnum::OK;

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top