简体   繁体   English

C ++ DirectX11返回一个Enum类

[英]C++ DirectX11 Returning an Enum class

Header File: 头文件:

protected:
enum class GameState
    {
        nullState
        , firstState
        , secondState
    };

GameState gameState;

in the CPP file I want to return the state that gameState is currently at, how do I do this as enum is not a type? 在CPP文件中,我想返回gameState当前所在的状态,由于枚举不是类型,我该怎么做?

I tried doing: 我试着做:

int ReturnGameState()
{
    return this->gameState;
}

because I thought the enums were stored as ints but it says the return types are different. 因为我以为枚举被存储为整数,但是它说返回类型是不同的。

Thanks. 谢谢。

Of course you can. 当然可以。 Why do you have "class" in your enum declaration? 为什么在枚举声明中有“类”? That is not correct syntax. 那是不正确的语法。 The code below compiles just fine. 下面的代码可以很好地编译。

enum  GameState
    {
        nullState
        , firstState
        , secondState
    };

GameState ReturnGameState()
{
    GameState r = firstState; //example
    return r;
}

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

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