• <legend id='5ZS3k'><style id='5ZS3k'><dir id='5ZS3k'><q id='5ZS3k'></q></dir></style></legend>
    1. <tfoot id='5ZS3k'></tfoot>

        <small id='5ZS3k'></small><noframes id='5ZS3k'>

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

        未命名结构的前向声明

        Forward declarations of unnamed struct(未命名结构的前向声明)

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

              • <small id='00PiH'></small><noframes id='00PiH'>

                <legend id='00PiH'><style id='00PiH'><dir id='00PiH'><q id='00PiH'></q></dir></style></legend>
                1. 本文介绍了未命名结构的前向声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  悬赏问题: 所以,这两个 Foo 不是一回事.美好的.第二种形式是在图书馆中给出的.鉴于我无法更改它,我该如何提前声明它?

                  Bounty question: So, these two Foos aren't the same thing. Fine. The second form is given in a library. How do I forward-declare it given that I can't change it?

                  我一直认为 C 和 C++ 允许重复声明,前提是没有重复定义.然后我在尝试编写扩展 C 库的 C++ 代码时遇到了这个问题.

                  I always thought C and C++ allowed repeated declarations provided that there were no repeated definitions. Then I came across this problem when trying to write C++ code which extends a C library.

                  struct Foo;
                  typedef struct {} Foo;
                  

                  出现以下错误:

                  'struct Foo' 先前声明为 'struct Foo'

                  'struct Foo' has a previous declaration as 'struct Foo'

                  我要提前申报,该死!这里有什么问题吗?

                  I want to forward-declare, darn it! What's wrong here?

                  推荐答案

                  typedef-ing anonymous struct 是一种早于 C++03 的实践,主要面向保持与 C99 之前的编译器的兼容性.

                  typedef-ing anonymous struct is a practice that pre-dates C++03 and is mainly oriented to retain compatibility with pre-C99 compilers.

                  鉴于这是 2011 年,而且 C++ 和 C 都发生了变化,我想知道为什么没有更新版本的此类库!

                  Given that this is 2011, and that both C++ and C are changed, I wonder why there is no more up-to-date version of such a library!

                  如果它不再处于开发阶段,你就不能离开",而只能生存"并改变它就是这样做的方式.如果仍在部署中,请将问题提交给开发团队.

                  If it is not in development anymore, you cannot "leave", but just "survive" and change it is the way to do that. If still in deployment, submit the issue to the development team.

                  如果您需要解决方法,请考虑结构可以继承.所以,写一个像

                  If you need a workaround, consider that struct can inherit. So, write a forward declaration like

                  struct MyFoo;
                  

                  并将其定义为

                  #include "old_library.h"
                  struct MyFoo: public Foo {};
                  

                  并且在您的所有代码中,忘记 Foo 并始终使用 MyFoo.

                  And in all your code, forget about Foo and always use MyFoo.

                  这篇关于未命名结构的前向声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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++程序中的堆栈溢出错误)

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

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

                    <tfoot id='SgH2e'></tfoot>

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