• <legend id='706va'><style id='706va'><dir id='706va'><q id='706va'></q></dir></style></legend>

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

      • <bdo id='706va'></bdo><ul id='706va'></ul>
      1. <tfoot id='706va'></tfoot>

        <small id='706va'></small><noframes id='706va'>

        C++ 枚举类可以有方法吗?

        Can a C++ enum class have methods?(C++ 枚举类可以有方法吗?)

      2. <legend id='jQCaj'><style id='jQCaj'><dir id='jQCaj'><q id='jQCaj'></q></dir></style></legend>

        <tfoot id='jQCaj'></tfoot>

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

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

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

                1. 本文介绍了C++ 枚举类可以有方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个带有两个值的枚举类,我想创建一个接收值的方法并返回另一个.我还想保持类型安全(这就是我使用枚举类而不是枚举的原因).

                  I have an enum class with two values, and I want to create a method which receives a value and returns the other one. I also want to maintain type safety(that's why I use enum class instead of enums).

                  http://www.cplusplus.com/doc/tutorial/other_data_types/ 没有提到任何关于方法的内容然而,我的印象是任何类型的类都可以有方法.

                  http://www.cplusplus.com/doc/tutorial/other_data_types/ doesn't mention anything about methods However, I was under the impression that any type of class can have methods.

                  推荐答案

                  不,他们不能.

                  我可以理解,C++11 中强类型枚举的 enum class 部分似乎暗示您的 enum 具有 class特质也是如此,但事实并非如此.我有根据的猜测是,关键字的选择受到了我们在 C++11 之前用于获取作用域枚举的模式的启发:

                  I can understand that the enum class part for strongly typed enums in C++11 might seem to imply that your enum has class traits too, but it's not the case. My educated guess is that the choice of the keywords was inspired by the pattern we used before C++11 to get scoped enums:

                  class Foo {
                  public:
                    enum {BAR, BAZ};
                  };
                  

                  然而,这只是语法.同样,enum class 不是 class.

                  However, that's just syntax. Again, enum class is not a class.

                  这篇关于C++ 枚举类可以有方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)

                  1. <legend id='ciug1'><style id='ciug1'><dir id='ciug1'><q id='ciug1'></q></dir></style></legend>
                      <tbody id='ciug1'></tbody>
                    • <bdo id='ciug1'></bdo><ul id='ciug1'></ul>

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

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