Why am I getting this 'enum' is not a class or a namespace error?

前端 未结 4 1990
粉色の甜心
粉色の甜心 2020-12-10 18:10

I need call a method with this signature in my Manager class:

void createPlayer(Player& player, PlayerType& playerType);

I have a P

4条回答
  •  我在风中等你
    2020-12-10 18:28

    Your error seems to be in this line: PlayerType t = PlayerType::FORWARD;

    As far as I know, the scope resolution operator (::) is not valid on regular C++98 enums unless your compiler supports them through non-standard extensions (like Visual Studio). Therefore you can't use it to reference an specific value from the enumerator.

    Also, C++98 enums have the problem of polluting the namespace in which they are defined which can lead to name clash. Luckily C++11 solved this introducing the enum class. For more information check Stroustrup's FAQ: http://www.stroustrup.com/C++11FAQ.html#enum

提交回复
热议问题