standards compliant way to typedef my enums
How can I get rid of the warning, without explicitly scoping the enum properly? The standards-comp开发者_运维知识库liant code would be to compare against foo::bar::mUpload
(see here), but the explicit scopes are really long and make the darn thing unreadable.
maybe there's another way that doesn't use typedef? i don't want to modify the enum--i didn't write it and its in use 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();
}
If the enum is defined within a class, the best that you can do is bring the class into your own scope and just use class_name::value
or define a typedef of the class. In C++03 the values of an enum are part of the enclosing scope (which in your case is the class). In C++0x/11 you will be able to qualify the values with the enum 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 usage will be correct (C++11):
typedef first::second::enclosing::the_enum my_enum;
assert( my_enum::one_value != my_enum::another );
You can enclose your enum into a namespace, and then use a using
statement on that namespace.
This obviously only works for enum's outside of class scope.
In your case I don't see why don't you refer to it as bar::mUpload
(after using namespace foo
, or using foo::bar
)
You can use a typedef for foo::bar:
typedef foo::bar fb;
//...
fb::baz m = fb::mUpload;
Or are you looking for something different?
精彩评论