C++ DirectX11 返回一个枚举类
C++ DirectX11 Returning an Enum class
头文件:
protected:
enum class GameState
{
nullState
, firstState
, secondState
};
GameState gameState;
在 CPP 文件中,我想返回 gameState 当前所处的状态,由于枚举不是一种类型,我该怎么做?
我尝试做:
int ReturnGameState()
{
return this->gameState;
}
因为我认为枚举存储为整数,但它说返回类型不同。
谢谢。
当然可以。 为什么枚举声明中有"类"? 这不是正确的语法。 下面的代码编译得很好。
enum GameState
{
nullState
, firstState
, secondState
};
GameState ReturnGameState()
{
GameState r = firstState; //example
return r;
}
相关文章:
- 我在 .h 中有一个枚举类,并且在.cpp错误中有一个运算符重载:与"运算符<<不匹配
- 给枚举一个整数,并在 C++ 中将其相关值作为字符串获取
- 我正在尝试创建一个枚举,但得到了"identifier expected error"
- C++如何将字符串数组中的一个点设置为枚举变量
- C++中一个非常简单的枚举类错误
- 如何编写一个错误结构,该结构可以包含不同的强键枚举作为错误代码
- 如何在交换机中将一个枚举值标记为不适当的大小写
- 从另一个C++文件中C++ "Importing"枚举类
- 如何声明另一个类中的枚举
- C/C :提取一个枚举的子集以形成新的枚举
- 随机生成一个没有重复元素的枚举数组 (C++)
- 有没有办法在一个枚举条目中存储多个值
- 为什么我的程序中的一个枚举具有奇怪的价值131075?
- 将一个枚举映射到另一个枚举
- 在Selene中包装一个枚举,以便在Lua中访问
- 为什么我不能将一个枚举作为另一个枚举的基础类型?
- 初始化一个枚举,比如它是一个类,以避免强制类型转换
- 我怎么能有一个枚举自定义类
- Typedef是C++中的一个枚举值
- C++ DirectX11 返回一个枚举类