Connecting Tech Pros Worldwide Help | Site Map

scope of enum

  #1  
Old October 20th, 2006, 03:05 PM
wenmang@yahoo.com
Guest
 
Posts: n/a
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, 03:15 PM
Victor Bazarov
Guest
 
Posts: n/a

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


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
enum handling change in VS 2005 Craig Klementowski answers 8 November 17th, 2005 03:04 PM
the use of enum. developer1996 answers 3 November 15th, 2005 11:52 AM
what is the scope of enum? Rouben Rostamian answers 5 November 14th, 2005 05:17 PM
GCC and forward declaration of enum Alexander Grigoriev answers 11 July 19th, 2005 06:30 PM