使用来自另一个类的枚举的 C++
c++ using enum from another 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
};
};
当我尝试在此示例中使用它时:
if(( (DWORD) adr.ProtectedByMagicShield & pFlags) == (DWORD) ProtectedByMagicShield){
//...
}
它说抛出错误:'ProtectedByMagicShield' : undeclared identifier...
pFlags
是一个DWORD
,我使用的是C++.NET。
if(( (DWORD) Adresy::ProtectedByMagicShield & pFlags) == (DWORD) Adresy::ProtectedByMagicShield){
//...
}
需要使用类名和范围标记 (::)以访问枚举的值。
这是因为枚举不是由类的任何特定实例拥有,而是由类本身拥有,例如静态 const 成员。
相关文章:
- 不带大括号的枚举形式
- 枚举环境变量的惯用C++14/C++17方法
- 类似枚举的计算常量
- 如何正确实现和访问运算符的各种自定义枚举器
- 错误:从"int"到枚举c++的转换无效
- C++中构造函数中的枚举
- 访问在 C++ 结构中声明的枚举变量
- 枚举类'classname'的多重定义
- 强枚举类型定义:Clang Bug 还是 C++11 标准不确定性?
- typedef 枚举和枚举类有什么区别?
- 为什么我的开关/机箱在使用枚举时默认?
- 标准::可选枚举的比较运算符
- C++两个源文件之间共享的枚举的静态实例
- 打印没有铸件的枚举可以在C++中吗?
- 枚举成员与静态 int 成员?
- C++:枚举:错误:应使用标识符而不是"}"
- 带有 c++ 的枚举(输入检查)
- 在 qml 中使用 Q_ENUM 和 Q_PROPERTY 作为枚举类
- 为什么 int 类型的枚举类值不能用作 int
- 在 C++ 中输出枚举类类型的向量元素