2012-07-06 110 views
1

我创建了一个类AdresyC++使用枚举从另一个类

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...

pFlags是一个DWORD,我正在使用C++。NET。

回答

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

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

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

+0

thx,它的工作:) – Luke 2012-07-06 19:28:46