简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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