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

    • <bdo id='vIOYk'></bdo><ul id='vIOYk'></ul>

      <legend id='vIOYk'><style id='vIOYk'><dir id='vIOYk'><q id='vIOYk'></q></dir></style></legend>

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

      <tfoot id='vIOYk'></tfoot>
      1. C++循环包含

        C++ circular include(C++循环包含)

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

                <tbody id='dFtB1'></tbody>

            • <small id='dFtB1'></small><noframes id='dFtB1'>

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

                1. <legend id='dFtB1'><style id='dFtB1'><dir id='dFtB1'><q id='dFtB1'></q></dir></style></legend>
                  本文介绍了C++循环包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我无法解决这个循环依赖问题;总是收到这个错误:不完整类型结构 GemsGame 的无效使用"我不知道为什么编译器不知道 GemsGame 的声明,即使我包含了 gemsgame.h两个类相互依赖(GemsGame 存储了一个 GemElements 的向量,而 GemElements 需要访问同一个向量)

                  I can't solve this circular dependency problem; always getting this error: "invalid use of incomplete type struct GemsGame" I don't know why the compiler doesn't know the declaration of GemsGame even if I included gemsgame.h Both classes depend on each other (GemsGame store a vector of GemElements, and GemElements need to access this same vector)

                  这是GEMELEMENT.H的部分代码:

                  Here is partial code of GEMELEMENT.H:

                  #ifndef GEMELEMENT_H_INCLUDED
                  #define GEMELEMENT_H_INCLUDED
                  
                  #include "GemsGame.h"
                  
                  class GemsGame;
                  
                  class GemElement {
                      private:
                          GemsGame* _gemsGame;
                  
                      public:
                          GemElement{
                              _gemsGame = application.getCurrentGame();
                              _gemsGame->getGemsVector();
                          }
                  };
                  
                  
                  #endif // GEMELEMENT_H_INCLUDED
                  

                  ...以及 GEMSGAME.H:

                  ...and of GEMSGAME.H:

                  #ifndef GEMSGAME_H_INCLUDED
                  #define GEMSGAME_H_INCLUDED
                  
                  #include "GemElement.h"
                  
                  class GemsGame {
                      private:
                          vector< vector<GemElement*> > _gemsVector;
                  
                      public:
                          GemsGame() {
                              ...
                          }
                  
                          vector< vector<GemElement*> > getGemsVector() {
                              return _gemsVector;
                          }
                  }
                  
                  #endif // GEMSGAME_H_INCLUDED
                  

                  推荐答案

                  删除 #include 指令,您已经预先声明了类.

                  Remove the #include directives, you already have the classes forward declared.

                  如果您的 A 类在其定义中需要了解 B 类的详细信息,那么您需要包含 B 类的标头.如果类 A 只需要知道类 B 存在,比如类 A 只持有一个指向类 B 实例的指针,那么前向声明就足够了,在这种情况下,#include 不是需要.

                  If your class A needs, in its definition, to know something about the particulars of class B, then you need to include class B's header. If class A only needs to know that class B exists, such as when class A only holds a pointer to class B instances, then it's enough to forward-declare, and in that case an #include is not needed.

                  这篇关于C++循环包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is Type(::x); valid?(是类型(::x);有效的?)
                  Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                  Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                  Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                  No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                  Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)

                  <small id='4nt0k'></small><noframes id='4nt0k'>

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

                      <tfoot id='4nt0k'></tfoot>
                      • <bdo id='4nt0k'></bdo><ul id='4nt0k'></ul>
                        <legend id='4nt0k'><style id='4nt0k'><dir id='4nt0k'><q id='4nt0k'></q></dir></style></legend>