Standard compliant typedef method my enums

How can I get rid of the warning without explicitly specifying enum correctly? Code conforming to standards should be compared with foo::bar::mUpload (see here ), but the explicit areas are really long and make the black thing unreadable.

maybe there is another way that does not use typedef? I do not want to change the enumeration - I did not write it and did not use it elsewhere.

warning C4482: nonstandard extension used: enum 'foo::bar::baz' used in qualified name

 namespace foo { class bar { enum baz {mUpload = 0, mDownload}; } } typedef foo::bar::baz mode_t; mode_t mode = getMode(); if (mode == mode_t::mUpload) //C4482 { return uploadthingy(); } else { assert(mode == mode_t::mDownload); //C4482 return downloadthingy(); } 
+3
c ++ enums
Jul 19 '10 at 21:10
source share
3 answers

If an enumeration is defined inside a class, the best you can do is bring the class into its own scope and simply use class_name::value or define the typedef of the class. In C ++ 03, enum values ​​are part of the scope (which in your case is a class). In C ++ 0x / 11, you can assign values ​​with an enumeration name:

 namespace first { namespace second { struct enclosing { enum the_enum { one_value, another }; } }} using first::second::enclosing; typedef first::second::enclosing the_enclosing; assert( enclosing::one_value != the_enclosing::another ); 

In the future, your use will be correct (C ++ 11):

 typedef first::second::enclosing::the_enum my_enum; assert( my_enum::one_value != my_enum::another ); 
+3
Jul 19 '10 at 21:19
source share

You can enclose your enumeration in a namespace, and then use the using statement in that namespace.

This explicitly only works for enumerations outside the class.

In your case, I don’t understand why you are not referring to it as bar::mUpload (after using namespace foo or using foo::bar )

+1
Jul 19 '10 at 21:13
source share

You can use typedef for foo :: bar:

 typedef foo::bar fb; //... fb::baz m = fb::mUpload; 

Or are you looking for something else?

0
Jul 19 '10 at 21:19
source share



All Articles