【问题标题】:c++ using enum from another classc++ 使用来自另一个类的枚举
【发布时间】:2012-07-07 06:45:28
【问题描述】:

我创建了一个类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。

【问题讨论】:

    标签: c++ .net dword


    【解决方案1】:
    if(( (DWORD) Adresy::ProtectedByMagicShield & pFlags) == (DWORD) Adresy::ProtectedByMagicShield){
        //...
    }
    

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-10
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多