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

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

    <legend id='nv2YZ'><style id='nv2YZ'><dir id='nv2YZ'><q id='nv2YZ'></q></dir></style></legend>
      <bdo id='nv2YZ'></bdo><ul id='nv2YZ'></ul>

      1. 如何在 C++ 中实现无操作宏(或模板)?

        时间:2023-05-25
      2. <small id='UD29f'></small><noframes id='UD29f'>

      3. <legend id='UD29f'><style id='UD29f'><dir id='UD29f'><q id='UD29f'></q></dir></style></legend>
          <tbody id='UD29f'></tbody>

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

                  <tfoot id='UD29f'></tfoot>
                  本文介绍了如何在 C++ 中实现无操作宏(或模板)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  如何在 C++ 中实现 no-op 宏?

                  How do I implement no-op macro in C++?

                  #include <iostream>   
                  
                  #ifdef NOOP       
                      #define conditional_noop(x) what goes here?   
                  #else       
                      #define conditional_noop(x) std::cout << (x)   
                  #endif   
                  int main() {       
                      conditional_noop(123);   
                  }
                  

                  我希望在定义 NOOP 时不执行任何操作,并在未定义 NOOP 时打印123".

                  I want this to do nothing when NOOP is defined and print "123", when NOOP is not defined.

                  推荐答案

                  如前所述 - 没有.
                  此外,您的代码中存在印刷错误.
                  它应该是 #else 而不是 #elif.如果是#elif,则后面跟着新的条件

                  As mentioned before - nothing.
                  Also, there is a misprint in your code.
                  it should be #else not #elif. if it is #elif it is to be followed by the new condition

                  #include <iostream>   
                  
                  #ifdef NOOP       
                      #define conditional_noop(x) do {} while(0)
                  #else       
                      #define conditional_noop(x) std::cout << (x)   
                  #endif  
                  

                  玩得开心编码!按照另一个答案中的建议添加了 [do] 结构以提高稳健性.

                  Have fun coding! added the [do] construct for robustness as suggested in another answer.

                  这篇关于如何在 C++ 中实现无操作宏(或模板)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:专用模板类的静态成员初始化 下一篇:在 C++ 编译时计算和打印阶乘

                  相关文章

                  最新文章

                    <bdo id='SHQiI'></bdo><ul id='SHQiI'></ul>
                  <tfoot id='SHQiI'></tfoot>

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

                2. <small id='SHQiI'></small><noframes id='SHQiI'>