C ++:尚未声明 [英] C++: Has Not Been Declared

查看:84
本文介绍了C ++:尚未声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处都看到了这种类型的错误,尽管我已经看了答案,但似乎都没有帮助。

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 ++:尚未声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆