使用枚举内部类型 - 编译器警告C4482 C ++ [英] Using enum inside types - Compiler warning C4482 C++
本文介绍了使用枚举内部类型 - 编译器警告C4482 C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的类中的一个方法中使用枚举的完全限定名。但我得到编译器警告,说:警告C4482:非标准扩展使用:枚举'Foo'使用在限定名。在C ++中,我们需要使用枚举而没有限定名称吗?但国际海事组织,看起来丑陋。
I am using fully qualified name of the enum inside a method in one of my class. But I am getting compiler warning which says "warning C4482: nonstandard extension used: enum 'Foo' used in qualified name". In C++, do we need to use enums without the qualified name? But IMO, that looks ugly.
有任何想法吗?
推荐答案
一个新的命名空间,枚举中的值直接在周围范围中可用。所以你得到:
Yes, enums don't create a new "namespace", the values in the enum are directly available in the surrounding scope. So you get:
enum sample {
SAMPLE_ONE = 1,
SAMPLE_TWO = 2
};
int main() {
std::cout << "one = " << SAMPLE_ONE << std::endl;
return 0;
}
这篇关于使用枚举内部类型 - 编译器警告C4482 C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文