C++ DirectX11 返回一个枚举类

C++ DirectX11 Returning an Enum class

本文关键字:一个 枚举 DirectX11 返回 C++      更新时间:2023-10-16

头文件:

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;
}