c ++使用另一个类的枚举

时间:2012-07-06 19:21:58

标签: c++ .net dword

我创建了一个班级Adresy

class Adresy {
    public:
        static const DWORD hp = 0x947000;
        static const DWORD mp = 0x7B2084;
        static const DWORD cap = 0x97EE94;
        enum Flags
        {
            None = 0,
            Poisoned = 1,
            Burning = 2,
            ProtectedByMagicShield = 16
        };
};

当我尝试在此示例中使用它时:

if(( (DWORD) adr.ProtectedByMagicShield & pFlags) == (DWORD) ProtectedByMagicShield){
//...
}

它会抛出错误:'ProtectedByMagicShield' : undeclared identifier...

pFlagsDWORD,我正在使用C ++ .NET。

1 个答案:

答案 0 :(得分:5)

if(( (DWORD) Adresy::ProtectedByMagicShield & pFlags) == (DWORD) Adresy::ProtectedByMagicShield){
    //...
}

您需要使用类名和作用域标记(::)来访问枚举的值。

这是因为枚举不是由类的任何特定实例拥有,而是由类本身拥有,就像静态const成员一样。