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

      <i id='Hbhbe'><tr id='Hbhbe'><dt id='Hbhbe'><q id='Hbhbe'><span id='Hbhbe'><b id='Hbhbe'><form id='Hbhbe'><ins id='Hbhbe'></ins><ul id='Hbhbe'></ul><sub id='Hbhbe'></sub></form><legend id='Hbhbe'></legend><bdo id='Hbhbe'><pre id='Hbhbe'><center id='Hbhbe'></center></pre></bdo></b><th id='Hbhbe'></th></span></q></dt></tr></i><div id='Hbhbe'><tfoot id='Hbhbe'></tfoot><dl id='Hbhbe'><fieldset id='Hbhbe'></fieldset></dl></div>
      <legend id='Hbhbe'><style id='Hbhbe'><dir id='Hbhbe'><q id='Hbhbe'></q></dir></style></legend>
      • <bdo id='Hbhbe'></bdo><ul id='Hbhbe'></ul>
      <tfoot id='Hbhbe'></tfoot>
    1. c++ 将枚举值标记为已弃用?

      c++ mark enum value as deprecated?(c++ 将枚举值标记为已弃用?)
        <tbody id='tZwdT'></tbody>
        <i id='tZwdT'><tr id='tZwdT'><dt id='tZwdT'><q id='tZwdT'><span id='tZwdT'><b id='tZwdT'><form id='tZwdT'><ins id='tZwdT'></ins><ul id='tZwdT'></ul><sub id='tZwdT'></sub></form><legend id='tZwdT'></legend><bdo id='tZwdT'><pre id='tZwdT'><center id='tZwdT'></center></pre></bdo></b><th id='tZwdT'></th></span></q></dt></tr></i><div id='tZwdT'><tfoot id='tZwdT'></tfoot><dl id='tZwdT'><fieldset id='tZwdT'></fieldset></dl></div>
        • <bdo id='tZwdT'></bdo><ul id='tZwdT'></ul>
          <tfoot id='tZwdT'></tfoot>
        • <legend id='tZwdT'><style id='tZwdT'><dir id='tZwdT'><q id='tZwdT'></q></dir></style></legend>

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

              • 本文介绍了c++ 将枚举值标记为已弃用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                是否可以将枚举值标记为已弃用?

                Is it possible to mark an enum value as deprecated?

                例如

                enum MyEnum {
                    firstvalue = 0
                    secondvalue,
                    thirdvalue, // deprecated
                    fourthvalue
                };
                

                二等奖的解决方案是 ifdef MSVC 和 GCC 解决方案.

                A second prize solution would be to ifdef a MSVC and a GCC solution.

                推荐答案

                你可以这样做:

                enum MyEnum {
                    firstvalue = 0,
                    secondvalue,
                    thirdvalue, // deprecated
                    fourthvalue
                };
                #pragma deprecated(thirdvalue)
                

                然后每当使用该变量时,编译器将输出以下内容:

                then when ever the variable is used, the compiler will output the following:

                warning C4995: 'thirdvalue': name was marked as #pragma deprecated
                

                编辑
                这看起来有点 hacky,我没有 GCC 编译器来确认(有人可以为我做这件事吗?)但它应该可以工作:

                EDIT
                This looks a bit hacky and i dont have a GCC compiler to confirm (could someone do that for me?) but it should work:

                enum MyEnum {
                    firstvalue = 0,
                    secondvalue,
                #ifdef _MSC_VER
                    thirdvalue,
                #endif
                    fourthvalue = secondvalue + 2
                };
                
                #ifdef __GNUC__
                __attribute__ ((deprecated)) const MyEnum thirdvalue = MyEnum(secondvalue + 1);
                #elif defined _MSC_VER
                #pragma deprecated(thirdvalue)
                #endif
                

                这是我的回答和 MSalters 的回答的结合

                it's a combination of my answer and MSalters' answer

                这篇关于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?)
                <i id='gmJId'><tr id='gmJId'><dt id='gmJId'><q id='gmJId'><span id='gmJId'><b id='gmJId'><form id='gmJId'><ins id='gmJId'></ins><ul id='gmJId'></ul><sub id='gmJId'></sub></form><legend id='gmJId'></legend><bdo id='gmJId'><pre id='gmJId'><center id='gmJId'></center></pre></bdo></b><th id='gmJId'></th></span></q></dt></tr></i><div id='gmJId'><tfoot id='gmJId'></tfoot><dl id='gmJId'><fieldset id='gmJId'></fieldset></dl></div>

                  <legend id='gmJId'><style id='gmJId'><dir id='gmJId'><q id='gmJId'></q></dir></style></legend>
                    <tbody id='gmJId'></tbody>
                  <tfoot id='gmJId'></tfoot>

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

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