开发者

Use enum inside struct inside class?

开发者 https://www.devze.com 2023-04-12 07:21 出处:网络
I have wrapped a struct around an enum to get a scoped enum.E.g.: namespace Xyz { struct SortDirection { enum Enum {ASC, DESC};

I have wrapped a struct around an enum to get a scoped enum. E.g.:

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:

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 enu开发者_StackOverflow社区m works fine not inside the struct, but as soon as I wrap it in a struct I get this error.


Try

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.


//This is right code.

private:     
    struct SomeType 
    {        
        enum Columns 
        {         
            ROW_NUMBER_COLUMN,
            NAME_COLUMN,
            AGE_COLUMN,
            COLUMN_MAX_COUNT_
        };
     }; 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号