I am trying to remove the warnings from a class I am working on.
The warning is as follows:
Warning C4482: nonstandard extension used: enum 'MyEnum' used in qualified name
I understand that the warning is caused by attempting to access one of the values in the enum like so:
//Declared in a C header file.
enum MyEnum
{
Value1,
Value2,
Value3
};
//Exists in some other .cpp file.
void SomeFunc()
{
MyEnum::Value1; //Generates warning C4482
}
FYI: SomeFunc() exists in a .cpp file but the enum is declared in a C header file.
So one way I can remove the warning is to replace MyEnum::Value1 with just Value1. However I would much rather refer to the enum values with MyEnum::Value1 as I like that it is more explicit.
So if I was using just C++ I could change the enum like so:
namespace MyEnum
{
enum
{
Value1,
Value2,
Value3
};
}
However the enum exists in a C header file and so I can't wrap the enum in a namespace. I also can't move the enum in to a C++ header file as other files are already dependent on the enum.
One way I considered was to wrap the enum in a struct:
struct MyEnum
{
enum Type
{
Value1,
Value2,
Value3
};
};
Which would allow me to access the values with MyEnum::Value1 without raising the warning.
However, is there a better way to achieve this?
Furthermore I've also had situations where the enum existed in a C++ file but it was scoped to a class:
class MyClass
{
enum MyEnum
{
Value1,
Value2,
Value3
};
};
I don't want to move it out of the class because the class provides the encapsulation for the enum but I also can't wrap the enum in a namespace because namespaces are not allowed in the class declaration. Is there a better way to implement the same behavior (MyEnum::Value1) in this situation without raising the same warning?
FYI2: I am limited to implementations that are allowed by vc10.