[英]Declaration with no type
我很困惑。
我這樣做:
#include <vector>
// List iteration
typedef vector<registeredObject>::iterator iterator;
typedef vector<registeredObject>::const_iterator const_iterator;
vector<registeredObject>::iterator begin(void);
vector<registeredObject>::const_iterator begin(void) const;
vector<registeredObject>::iterator end(void);
vector<registeredObject>::const_iterator end(void) const;
我收到如下錯誤:
.: error: ISO C++ forbids declaration of 'vector' with no type
.: error: expected ';' before '<' token
對於上述向量的每一種用途。 該代碼在較舊的CodeWarrior中編譯,但是XCode抱怨。 有什么問題
有很好的參考嗎?
[編輯]這里是整個報頭這里
vector
在命名空間std
:
typedef std::vector<registeredObject>::iterator iterator;
另外,為什么要定義這些類型然后不使用它們呢?
typedef std::vector<registeredObject> container;
typedef container::iterator iterator;
typedef container::const_iterator const_iterator;
iterator begin(void);
const_iterator begin(void) const;
iterator end(void);
const_iterator end(void) const;
還要考慮一下,也許您還沒有定義registeredObject
。 嘗試使用int
來確保。
現在我們看到registeredObject
是一個模板參數,您需要typename
:
typedef typename std::vector<registeredObject> container;
typedef typename container::iterator iterator;
typedef typename container::const_iterator const_iterator;
這就是為什么。 不過,不要忘記其他事情。 您仍然需要std::
,並實際使用定義的類型。 (這兩個類都必須解決。)
請注意這是更為常見的是使用T
作為模板類型。 然后,對typedef
慷慨大方也很常見:
typedef T value_type;
typedef std::vector<value_type> container;
typedef typename container::iterator iterator;
typedef typename container::const_iterator const_iterator;
並在您的課堂上使用它們。 (即,使用container mRegistryList;
相反)
是否聲明了registeredObject? 您是否包含RegisteredObject.h?
type is defined in a file somewhere, but is not included in this header file. 如果我不得不猜測,我會說類型是在某個文件中定義的,但是不包含在此頭文件中。
before and this would work. 一個.CPP文件可能恰好在之前包含 ,這將起作用。 , which would then produce an error. 但是,另一個文件可能只是包含 ,這將產生一個錯誤。
目前沒有足夠的代碼來確定。 也許您可以更改示例以顯示所有頭文件內容,直到第一個錯誤為止。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.