已經詢問了與此錯誤有關的幾個問題,但它們中的每一個實際上都與未在使用前聲明的對象或類型有關。例如:另一個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