3

How can I get rid of the warning, without explicitly scoping the enum properly? The standards-compliant 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();
}
Community
  • 1
  • 1
Dustin Getz
  • 21,282
  • 15
  • 82
  • 131

3 Answers3

3

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 );
David Rodríguez - dribeas
  • 204,818
  • 23
  • 294
  • 489
1

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)

EFraim
  • 12,811
  • 4
  • 46
  • 62
  • what if i don't want to modify the enum? i didn't write it and its in use elsewhere. – Dustin Getz Jul 19 '10 at 21:14
  • The only way to get rid of that warning in that case is to name the values `foo::bar::mUpload`, etc. You could make your typedef `typedef foo::bar mode_t` but of course, then you could use a `mode_t` anywhere that a `foo::bar` is expected... – Dean Harding Jul 19 '10 at 21:15
0

You can use a typedef for foo::bar:

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

Or are you looking for something different?

jon hanson
  • 8,722
  • 2
  • 37
  • 61