问题描述
我到处都看到了这种类型的错误,尽管我已经看了答案,但似乎都没有帮助。
I have seen this type of error everywhere and, although I have looked at the answers, none seem to help.
我在下一篇文章中遇到以下错误代码:
I get the following error with the following piece of code:
错误:未声明 A
Bh:
#include "A.h"
class B{
public:
static bool doX(A *a);
};
Ah:
include "B.h"
class A{};
为了核对我已经尝试过的事情的清单:
-名称拼写正确地
-A在啊
-没有命名空间
-没有模板
-没有宏
To run off a checklist of things I've already tried:- Names are spelled correctly- A is in A.h- There are no namespaces- No templates- No macros
我有其他类可以找到A就好了。我唯一能想到的是静态导致了问题。
I have other classes with can find A just fine. The only thing I can think of is that 'static' is causing a problem.
推荐答案
替换包括
和前向声明:
//B.h
class A;
class B{
public:
static bool doX(A *a);
};
仅在需要时才包含文件。
Include files only when you have to.
此外,使用包括防护罩。这样可以防止其他令人讨厌的问题,例如重新定义&这样的。
Also, use include guards. This will prevent other nasty issues like re-definitions & such.
这篇关于C ++:尚未声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!