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

      1. <legend id='zKZqN'><style id='zKZqN'><dir id='zKZqN'><q id='zKZqN'></q></dir></style></legend>
        <tfoot id='zKZqN'></tfoot>

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

        错误:尽管包含头文件,但尚未声明类,并且代码在其他地方编译得很好

        error: Class has not been declared despite header inclusion, and the code compiling fine elsewhere(错误:尽管包含头文件,但尚未声明类,并且代码在其他地方编译得很好)
      3. <small id='4CXS3'></small><noframes id='4CXS3'>

        <tfoot id='4CXS3'></tfoot>

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

                    <tbody id='4CXS3'></tbody>
                  本文介绍了错误:尽管包含头文件,但尚未声明类,并且代码在其他地方编译得很好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以我有一个类包含在另一个类中,该类不断抛出形式为错误:'问题类'尚未声明的编译错误.文件是这样设置的:

                  So I have a class included in another class that keeps throwing a compile error of the form "error: 'ProblemClass' has not been declared. The files are set up thusly:

                  #ifndef PROBLEMCLASS_H
                  #define PROBLEMCLASS_H
                  
                  #include <iostream>
                  #include <cmath>
                  
                  class ProblemClass
                  {
                    public:
                  
                      virtual void Init() = 0;
                  };
                  
                  #endif
                  

                  发生错误的类如下所示:

                  and the class where the error occurs looks like this:

                  #ifndef ACLASS_H
                  #define ACLASS_H
                  
                  #include "problemclass.h"
                  
                  class AClass : public Base
                  {
                    public:
                  
                      void DoSomething(ProblemClass* problem);
                  
                  };
                  
                  #endif
                  

                  编译错误发生在 void Dosomething();

                  The compile error occurs at void Dosomething();

                  我知道这里的代码不足以解决问题.我一直无法创建一个可以重现它的最小示例.所以我的问题要笼统得多;什么样的事情可能会导致这种情况?有什么我应该特别寻找的东西,或者我应该遵循一些查询来追踪它吗?

                  I'm aware the code here isn't enough to solve the problem. I've been unable to create a minimal example that can reproduce it. So my question is much more general; what sort of things might cause this? Is there anything in particular I should look for, or some line of enquiry I should be following to track it down?

                  这段代码在几乎相同的项目版本中编译得很好.

                  This code compiles fine in an almost identical version of the project.

                  无论多么模糊,任何形式的帮助都将不胜感激.我在 win 7 64 位中使用代码块 10.05 和 mingw4.4.1.

                  Help of any sort would be greatly appreciated, no matter how vague. I'm using codeblocks 10.05 with mingw4.4.1 in win 7 64 bit.

                  推荐答案

                  您似乎是在说您显示的代码实际上并未产生您遇到的编译器错误.所以我们只能猜测.以下是一些可能性:

                  You seem to be saying that the code you are showing doesn't actually produce the compiler error that you are having a problem with. So we can only guess. Here are some possibilities:

                  • 您可能忘记在使用 ProblemClass 的文件中包含 problemclass.h.
                  • 您可能在 ProblemClass 自己的头文件中或在您使用它的地方拼错了名称.如果是大写错误,例如编写 ProblemclassproblemClass 而不是 ProblemClass,这可能很难被发现.
                  • 您可能将包含保护 #defines 从一个头文件复制粘贴到另一个头文件,然后忘记更改定义的名称.那么只有这两个包含的头文件中的第一个才会生效.
                  • 您可以将 ProblemClass 放在命名空间 A 中,在这种情况下,您必须将 ProblemClass 称为 A::ProblemClass 如果您是从名称空间 A 之外引用它.
                  • 您可能正在使用模板并且不期望两阶段查找以它确实.
                  • 您可能在包含中拼错了文件名.如果您在拼写错误的名称下还有该文件的旧版本,则编译器不会报告错误.
                  • 您可以使 ProblemClass 成为一个只有在包含 problemclass.h 后才能定义的宏,在这种情况下,您看到的是 ProblemClass被宏预处理器替换为其他内容.
                  • 您可以在头文件中定义 ProblemClass 而不是 problemclass.h,然后 problemclass.h 实际上定义了其他东西.莉>
                  • You could have forgot to include problemclass.h from the file where you are using ProblemClass.
                  • You could have misspelled the name of ProblemClass either in its own header file or in the place where you are using it. This can be hard to spot if it is a capitalization error such as writing Problemclass or problemClass instead of ProblemClass.
                  • You could have copy-pasted your inclusion guard #defines from one header file to another and then forgot to change the defined names. Then only the first of those two included header files would take effect.
                  • You could have placed ProblemClass in a namespace A, in which case you must refer to ProblemClass as A::ProblemClass if you are referring to it from outside the namespace A.
                  • You may be using templates and not expecting two-phase lookup to work the way it does.
                  • You could have misspelled the file name in your include. The compiler would not report an error on that if you also have an old version of that file under the misspelled name.
                  • You could have made ProblemClass a macro that only gets defined after you include problemclass.h, in which case what you see as ProblemClass gets replaced by something else by the macro preprocessor.
                  • You could have defined ProblemClass in a header file other than problemclass.h and then problemclass.h actually defines something else.

                  这篇关于错误:尽管包含头文件,但尚未声明类,并且代码在其他地方编译得很好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 作为模板参数时出错)

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

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

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

                            <tfoot id='ggcIC'></tfoot>