什么是“静态枚举"?在C ++中意味着什么? [英] What does "static enum" mean in C++?
问题描述
我最近遇到了这个问题:
I recently came across this:
static enum Response{
NO_ERROR=0,
MISSING_DESCRIPTOR,
...
};
它可以在Microsoft VS2005下编译并工作.但是,我不确定静态"修饰符应该做什么.与以下内容有何不同?
It compiles and works under Microsoft VS2005. However, I'm not sure what the 'static' modifier is supposed to do. Is it any different from the following?
enum Response {
NO_ERROR=0,
MISSING_DESCRIPTOR,
...
};
推荐答案
仅删除省略号的确切代码不是有效的C ++.您不能在enum
声明中使用static
存储类说明符;在那里没有任何意义(只能将对象,函数和匿名联合声明为static
).
That exact code, with just the ellipsis removed, is not valid C++. You can't use the static
storage class specifier in an enum
declaration; it doesn't make any sense there (only objects, functions, and anonymous unions can be declared static
).
但是,您可以在一个声明中声明一个enum
和一个变量:
You can, however, declare an enum
and a variable all in one declaration:
static enum Response {
NO_ERROR = 0,
MISSING_DESCRIPTOR
} x;
此处的static
适用于x
,实际上与您说的相同:
The static
here applies to x
and it is effectively the same as if you said:
enum Response {
NO_ERROR = 0,
MISSING_DESCRIPTOR
};
static Response x;
这篇关于什么是“静态枚举"?在C ++中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!