所以我有一个类包含在另一个类中,该类不断抛出形式为错误:'问题类'尚未声明的编译错误.文件是这样设置的:
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
自己的头文件中或在您使用它的地方拼错了名称.如果是大写错误,例如编写 Problemclass
或 problemClass
而不是 ProblemClass
,这可能很难被发现.#defines
从一个头文件复制粘贴到另一个头文件,然后忘记更改定义的名称.那么只有这两个包含的头文件中的第一个才会生效.ProblemClass
放在命名空间 A
中,在这种情况下,您必须将 ProblemClass
称为 A::ProblemClass
如果您是从名称空间 A
之外引用它.ProblemClass
成为一个只有在包含 problemclass.h
后才能定义的宏,在这种情况下,您看到的是 ProblemClass
被宏预处理器替换为其他内容.ProblemClass
而不是 problemclass.h
,然后 problemclass.h
实际上定义了其他东西.莉>problemclass.h
from the file where you are using ProblemClass
.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
.#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.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
.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.ProblemClass
in a header file other than problemclass.h
and then problemclass.h
actually defines something else.这篇关于错误:尽管包含头文件,但尚未声明类,并且代码在其他地方编译得很好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!