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

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

      1. 我可以重新定义一个 C++ 宏然后再定义它吗?

        时间:2023-06-29
          <bdo id='qbx5J'></bdo><ul id='qbx5J'></ul>
          1. <tfoot id='qbx5J'></tfoot>
              <legend id='qbx5J'><style id='qbx5J'><dir id='qbx5J'><q id='qbx5J'></q></dir></style></legend>

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

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

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

                  问题描述

                  我在我的代码中同时使用了 JUCE 库和一些 Boost 头文件.Juce 将T"定义为宏(groan),而 Boost 在其模板定义中经常使用T".结果是,如果您以某种方式在 Boost 头文件之前包含 JUCE 头文件,预处理器会在 Boost 代码中扩展 JUCE 宏,然后编译器就会无可救药地丢失.

                  I am using both the JUCE Library and a number of Boost headers in my code. Juce defines "T" as a macro (groan), and Boost often uses "T" in it's template definitions. The result is that if you somehow include the JUCE headers before the Boost headers the preprocessor expands the JUCE macro in the Boost code, and then the compiler gets hopelessly lost.

                  在大多数情况下,保持我的包含顺序正确并不难,但是当您有一个包含其他一些类的 JUCE 类并且在链的某处某个文件包含 Boost 时,它会变得棘手,如果其中任何一个文件之前,它需要 JUCE 包含您遇到麻烦.

                  Keeping my includes in the right order isn't hard most of the time, but it can get tricky when you have a JUCE class that includes some other classes and somewhere up the chain one file includes Boost, and if any of the files before it needed a JUCE include you're in trouble.

                  我最初希望解决这个问题

                  My initial hope at fixing this was to

                  #undef T
                  

                  在 Boost 的任何包含之前.但问题是,如果我不重新定义它,那么其他代码就会因为没有声明T"而感到困惑.

                  before any includes for Boost. But the problem is, if I don't re-define it, then other code gets confused that "T" is not declared.

                  然后我想也许我可以像这样做一些循环#define技巧:

                  I then thought that maybe I could do some circular #define trickery like so:

                  // some includes up here
                  #define ___T___ T
                  #undef T
                  // include boost headers here
                  #define T ___T___
                  #undef ___T___
                  

                  丑陋,但我认为它可能有用.

                  Ugly, but I thought it may work.

                  遗憾的是没有.我在使用T"作为宏的地方出现错误

                  Sadly no. I get errors in places using "T" as a macro that

                  '___T___' was not declared in this scope.
                  

                  有没有办法让这两个库可靠地协同工作?

                  Is there a way to make these two libraries work reliably together?

                  推荐答案

                  正如 greyfade 所指出的,你的 ___T___ 技巧不起作用,因为预处理器是一个非常简单的生物.另一种方法是使用 pragma 指令:

                  As greyfade pointed out, your ___T___ trick doesn't work because the preprocessor is a pretty simple creature. An alternative approach is to use pragma directives:

                   // juice includes here
                   #pragma push_macro("T")
                   #undef T
                   // include boost headers here
                   #pragma pop_macro("T")
                  

                  这应该适用于 MSVC++,并且 GCC 添加了对 pop_macropush_macro 的支持以与其兼容.虽然从技术上讲,它是依赖于实现的,但我认为没有一种标准的方法可以暂时取消定义.

                  That should work in MSVC++ and GCC has added support for pop_macro and push_macro for compatibility with it. Technically it is implementation-dependent though, but I don't think there's a standard way of temporarily suppressing the definition.

                  这篇关于我可以重新定义一个 C++ 宏然后再定义它吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何解码 boost 库命名? 下一篇:boost::spirit::qi 重复解析输出

                  相关文章

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

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

                      <tfoot id='OskOD'></tfoot>

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