• <legend id='Ohlme'><style id='Ohlme'><dir id='Ohlme'><q id='Ohlme'></q></dir></style></legend>

    1. <small id='Ohlme'></small><noframes id='Ohlme'>

        <bdo id='Ohlme'></bdo><ul id='Ohlme'></ul>
        <i id='Ohlme'><tr id='Ohlme'><dt id='Ohlme'><q id='Ohlme'><span id='Ohlme'><b id='Ohlme'><form id='Ohlme'><ins id='Ohlme'></ins><ul id='Ohlme'></ul><sub id='Ohlme'></sub></form><legend id='Ohlme'></legend><bdo id='Ohlme'><pre id='Ohlme'><center id='Ohlme'></center></pre></bdo></b><th id='Ohlme'></th></span></q></dt></tr></i><div id='Ohlme'><tfoot id='Ohlme'></tfoot><dl id='Ohlme'><fieldset id='Ohlme'></fieldset></dl></div>

      1. <tfoot id='Ohlme'></tfoot>
      2. c ++如何在不同的枚举名称中使用相同的枚举成员名称而不会出错:重新定义;以前的定义是“枚举器"

        c++ how to have same enum members name in different enum names without getting err:redefinition; previous definition was #39;enumerator#39;(c ++如何在不同的枚举名称中使用相同的枚举成员名称而不会出错:重新定义;以前的定义是“枚举器) - IT屋-程
          <bdo id='ZFbDV'></bdo><ul id='ZFbDV'></ul>
        • <legend id='ZFbDV'><style id='ZFbDV'><dir id='ZFbDV'><q id='ZFbDV'></q></dir></style></legend>
                <tbody id='ZFbDV'></tbody>

              <tfoot id='ZFbDV'></tfoot>

                <small id='ZFbDV'></small><noframes id='ZFbDV'>

                <i id='ZFbDV'><tr id='ZFbDV'><dt id='ZFbDV'><q id='ZFbDV'><span id='ZFbDV'><b id='ZFbDV'><form id='ZFbDV'><ins id='ZFbDV'></ins><ul id='ZFbDV'></ul><sub id='ZFbDV'></sub></form><legend id='ZFbDV'></legend><bdo id='ZFbDV'><pre id='ZFbDV'><center id='ZFbDV'></center></pre></bdo></b><th id='ZFbDV'></th></span></q></dt></tr></i><div id='ZFbDV'><tfoot id='ZFbDV'></tfoot><dl id='ZFbDV'><fieldset id='ZFbDV'></fieldset></dl></div>

                1. 本文介绍了c ++如何在不同的枚举名称中使用相同的枚举成员名称而不会出错:重新定义;以前的定义是“枚举器"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

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

                  I have config file that I include in all my files there I have different enums but inside each enum there are same element names for example: config.h

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

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

                  But when I try to compile the project with calling the enums with the proper enum name

                  m_pNinjaPlayer = (NinjaPlayer*)GameFactory::Instance().getGameObj(GameObjectType::NINJA_PLAYER);
                      ComponentMadiator::Instance().Register(GameObjectTypeLocation::NINJA_PLAYER,m_pNinjaPlayer);
                  

                  我收到编译错误:

                  error C2365: 'NINJA_PLAYER' : redefinition; previous definition was 'enumerator' (..ClassesGameFactory.cpp)
                  2>          d:devcpp2dcocos2d-x-3.0cocos2d-x-3.0projectslettersfunclassesconfig.h(22) : see declaration of 'NINJA_PLAYER'
                  

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

                  How can I keep in the config.h several enums with different names BUT with same elements names ?

                  推荐答案

                  问题是旧式枚举没有作用域.您可以通过使用作用域枚举来避免此问题(前提是您的编译器具有相关的 C++11 支持):

                  The problem is that old-style enumerations are unscoped. You can avoid this problem (provided your compiler has the relevant C++11 support) by using scoped enumerations:

                  enum class GameObjectType { NINJA_PLAYER };
                  
                  enum class GameObjectTypeLocation { NONE, MASSAGE_ALL, NINJA_PLAYER };
                  

                  或者,您可以将旧式枚举放在命名空间中:

                  Alternatively, you can put your old-school enumerations in namespaces:

                  namespace foo
                  {
                    enum GameObjectType { NINJA_PLAYER };
                  } // namespace foo
                  
                  namespace bar
                  {
                    enum GameObjectTypeLocation { NONE, MASSAGE_ALL, NINJA_PLAYER };
                  } // namespace bar
                  

                  那么你的枚举值将是 foo::NINJA_PLAYERbar::NINJA_PLAYER

                  Then your enum values will be foo::NINJA_PLAYER, bar::NINJA_PLAYER etc.

                  这篇关于c ++如何在不同的枚举名称中使用相同的枚举成员名称而不会出错:重新定义;以前的定义是“枚举器"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)

                      <tbody id='ijqJ3'></tbody>
                    <i id='ijqJ3'><tr id='ijqJ3'><dt id='ijqJ3'><q id='ijqJ3'><span id='ijqJ3'><b id='ijqJ3'><form id='ijqJ3'><ins id='ijqJ3'></ins><ul id='ijqJ3'></ul><sub id='ijqJ3'></sub></form><legend id='ijqJ3'></legend><bdo id='ijqJ3'><pre id='ijqJ3'><center id='ijqJ3'></center></pre></bdo></b><th id='ijqJ3'></th></span></q></dt></tr></i><div id='ijqJ3'><tfoot id='ijqJ3'></tfoot><dl id='ijqJ3'><fieldset id='ijqJ3'></fieldset></dl></div>

                        <bdo id='ijqJ3'></bdo><ul id='ijqJ3'></ul>

                        <small id='ijqJ3'></small><noframes id='ijqJ3'>

                          • <legend id='ijqJ3'><style id='ijqJ3'><dir id='ijqJ3'><q id='ijqJ3'></q></dir></style></legend>
                            <tfoot id='ijqJ3'></tfoot>