已经询问了与此错误有关的几个问题,但它们中的每一个实际上都与未在使用前声明的对象或类型有关。例如:另一个C++未在此范围内声明错误
class A
{
public:
A_Object a_obj;
};
获取错误A_Object was not declared in this scope
意味着A_object
未在文件中的任何位置声明。
注意:这是我对错误的理解。
现在我有一个名为Account.h
文件,如下图所示:
#ifndef ADDRESS_H_
#define ADDRESS_H_
#include "Account.h"
typedef Account account_type;//Error here
class Address
{
//Fields and methods
};
#endif /* ADDRESS_H_ */
当我尝试编译该文件获得:
#ifndef ACCOUNT_H_
#define ACCOUNT_H_
class Account
{
//fields and methods
};
#endif /* ACCOUNT_H_ */
我也有第二个文件,如下所示叫Address.h
错误Account was not declared in this scope
。
任何想法为什么?
你的'#endif'在哪里? –
除了两个人现在提出的循环依赖之外,另一种可能是你有两个Account.h文件,而且你不包括你认为的那个。 – john
如果'class Address'不依赖于'class Account'的实现,那么你可以转发 - 声明它而不是包含它。 – Neil