warning C4482: 使用了非标准扩展: 限定名中使用了枚举

compiler warning (level 1) C4482
warning description:

使用了非标准扩展: 限定名中使用了枚举“enum”
当引用类型内的枚举时,无需指定枚举的名称。
文件范围的枚举定义相当于常量,也不需要限定名。

example: C4482(MS Visual Studio)

// C4482.cpp

// compile with: /c /W1

struct S {
   enum E { a };
};

int i = S::E::a; // C4482

int j = S::a; // OK


 

 

NOTE:
warring C4482:  nonstandard extension used: enum **** used in qualified name

enumeration:
1. Standard C++ does not allow enumeration names to be used as scopes  (GCC: error)
   Visual C++  is half-hearted on the matter. (warrning)
2. C# support enumeration names as scopes.

Workaround: (for MS Visual Stdio)
if you want to get rid of those obnoxious error message and you're using MS Visual Studio, encompass your statement in #pragma directives. For example,

#progma warning(push)
#progma warning(disable : 4482)
... (your statement here) ...
#progma warning(pop)
 

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

 

文章出处:http://www.diybl.com/course/3_program/c++/cppsl/2008619/126863.html

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值