相关疑难解决方法(0)

c ++如何在不同的枚举名称中使用相同的枚举成员名称而不会出现错误:redefinition; 以前的定义是'枚举'

我有我在所有文件中包含的配置文件,我有不同的枚举,但在每个枚举中有相同的元素名称,例如:config.h

enum GameObjectType
{
     NINJA_PLAYER

};
enum GameObjectTypeLocation
{
    NONE,
    MASSAGE_ALL,  //this is for ComponentMadiator
    NINJA_PLAYER


};
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用适当的枚举名称调用枚举来编译项目时

m_pNinjaPlayer = (NinjaPlayer*)GameFactory::Instance().getGameObj(GameObjectType::NINJA_PLAYER);
    ComponentMadiator::Instance().Register(GameObjectTypeLocation::NINJA_PLAYER,m_pNinjaPlayer);
Run Code Online (Sandbox Code Playgroud)

我收到编译错误:

error C2365: 'NINJA_PLAYER' : redefinition; previous definition was 'enumerator' (..\Classes\GameFactory.cpp)
2>          d:\dev\cpp\2d\cocos2d-x-3.0\cocos2d-x-3.0\projects\lettersfun\classes\config.h(22) : see declaration of 'NINJA_PLAYER'
Run Code Online (Sandbox Code Playgroud)

如何在config.h中保留几个具有不同名称但具有相同元素名称的枚举?

c++ enums

28
推荐指数
2
解决办法
1万
查看次数

标签 统计

c++ ×1

enums ×1