Warning C4482 - Enums  
Author Message
Steve Jackson





PostPosted: Visual C++ Language, Warning C4482 - Enums Top

Maybe this isn't the correct forum, perhaps if I ask the question this way. Is there anything wrong with the way I am using the enum below FigureNames is simply an enum {jack, jill, etc..}. When compiling, it get the following warning;

Warning 2 warning C4482: nonstandard extension used: enum 'Names' used in qualified name c:\Documents and Settings\Steve Jackson\My Documents\MySchool\C++\Assign1\Assign1\Assign1\Main.cpp 282

switch (name)

{

case Names::jack:

cout << "My name is jack!";

break;

}




Visual C++6  
 
 
Brian Kramer





PostPosted: Visual C++ Language, Warning C4482 - Enums Top

Standard C++, unlike C#, does not allow enumeration names to be used as scopes (but Visual C++ is half-hearted on the matter).  Remove Names:: and it will compile.
 
 
Steve Jackson





PostPosted: Visual C++ Language, Warning C4482 - Enums Top

Brian;

Thank you. My problem is that I have more than one enum with the same (internal) name. If I don't add Names::, I will get an error. Does this mean that one can never duplicate names within enums

Thanks



 
 
Brian Kramer





PostPosted: Visual C++ Language, Warning C4482 - Enums Top

That's the weakness of C++, unfortunately. Namespaces can be used to get around this limitation.
 
 
Steve Jackson





PostPosted: Visual C++ Language, Warning C4482 - Enums Top

Thank you. I'm taking C++ for a class. Normally, I hang around in vb.net. I have to say that C++ has yet to impress me. I suppose that it is faster and more flexible - but the difference in development time - wow!



 
 
Brian Kramer





PostPosted: Visual C++ Language, Warning C4482 - Enums Top

C++ is certainly harder to master than VB, but its popularity continues due to its flexibility and "to-the-metal" code generation. C# is a great compromise--you get the flexibility of C++, the safety and "intellisense" of VB, but at a cost of performance.

Brian


 
 
xpnctoc





PostPosted: Visual C++ Language, Warning C4482 - Enums Top

If you want to get rid of those obnoxious error messages and you're using MS Visual Studio, encompass your switch statement in #pragma directives. For example,

#pragma warning(push)
#pragma warning(disable : 4482)

... (your switch statement here) ...

#pragma warning(pop)

That tells the compiler not to report the C4482 warning for code within the block. You're essentially saying to the compiler, "Yes, I'm doing this intentionally. I know it's not standard, but I want it done anyway. So build my project and quit your whining!"

You can also refer to http://msdn2.microsoft.com/en-us/library/2c8f766e(VS.71).aspx for more info.

As far as C++ versus VB, aside from flexibility and "to-the-metal", there are some things that you just can't do in any managed language, be it VB or C#. If you've lived on VB up to this point, you must not have had to do any low-level programming like writing device drivers. And if you've only starting learning C++, you're not really in a position to be impressed or not. It takes at least a few years to really appreciate the differences in all 3 languages, and to see where C++ really shines.