Connecting Tech Pros Worldwide Help | Site Map

scope of enum

 
LinkBack Thread Tools Search this Thread
  #1  
Old October 20th, 2006, 02:05 PM
wenmang@yahoo.com
Guest
 
Posts: n/a
Default scope of enum

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?


  #2  
Old October 20th, 2006, 02:15 PM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: scope of enum

wenmang@yahoo.com wrote:
Quote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.