[英]Use enum inside struct inside class?
I have wrapped a struct around an enum to get a scoped enum. 我已经在一个枚举周围包裹了一个结构以获得一个有范围的枚举。 Eg:
例如:
namespace Xyz
{
struct SortDirection
{
enum Enum {ASC, DESC};
};
class MyClass
...
This works fine. 这很好。 Now I'm trying to define the same type of enum/struct combo but this time inside the class:
现在,我试图定义相同类型的enum / struct组合,但这一次在类中:
class MainDialog
{
public:
...
private:
struct SomeType
enum Columns {
ROW_NUMBER_COLUMN,
NAME_COLUMN,
AGE_COLUMN,
COLUMN_MAX_COUNT_
};
};
}
However this gives me an intellisense error: 但是,这给了我一个智能感知错误:
Error: invalid combination of type specifiers
错误:类型说明符的无效组合
When I try to compile I get: 当我尝试编译时,我得到:
1>c:\something\maindialog.h(80): error C2236: unexpected
'enum' 'MainDialog::Columns'. Did you forget a ';'?
The enum works fine not inside the struct, but as soon as I wrap it in a struct I get this error. 枚举不在结构内部正常运行,但是一旦将其包装在结构中,就会出现此错误。
尝试
struct SomeType { // Note the open brace
You've missed an opening brace. 您错过了一个开括号。 The compiler sees
struct SomeType enum Columns
and doesn't know what to do with it. 编译器看到
struct SomeType enum Columns
,并且不知道如何处理它。
//This is right code. //这是正确的代码。
private:
struct SomeType
{
enum Columns
{
ROW_NUMBER_COLUMN,
NAME_COLUMN,
AGE_COLUMN,
COLUMN_MAX_COUNT_
};
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.