Connecting Tech Pros Worldwide Forums | Help | Site Map

scope of enum

wenmang@yahoo.com
Guest
 
Posts: n/a
#1: Oct 20 '06
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?


Victor Bazarov
Guest
 
Posts: n/a
#2: Oct 20 '06

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