سؤال

I created a class 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...

pFlags is a DWORD, I'm using 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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top