简体   繁体   English

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

[英]c++ using enum from another class

I created a class Adresy : 我创建了一个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
        };
};

When I try to use it in this example: 在本示例中尝试使用它时:

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

it says throws the error: 'ProtectedByMagicShield' : undeclared identifier... 它说引发错误: 'ProtectedByMagicShield' : undeclared identifier...

pFlags is a DWORD , I'm using C++.NET. pFlagsDWORD ,我正在使用C ++。NET。

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

You need to use the class name and the scoping token (::) to access the values of the enum. 您需要使用类名称和作用域标记(::)来访问枚举的值。

This is because the enum isn't owned by any particular instance of your class but by the class itself, like the static const members. 这是因为枚举不属于您的类的任何特定实例,而是归于类本身,例如静态const成员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM