所以我有這樣一行:左側的[填空]必須有類/結構/聯合錯誤
ArrayList<Operation> operations();
現在,這是我的ArrayList類和我的操作結構:
typedef struct Operation {
char key;
int value;
} Operation;
template <class DT>
class ArrayList
{
private:
int _capacity;
int _size;
DT* elements;
public:
ArrayList();
~ArrayList();
void insert (DT&);
DT& operator[] (int);
};
ArrayList<DT>::ArrayList()
{
_capacity = 10;
_size = 0;
elements = new DT[10];
}
我沒有看到發佈其他方法的代碼的需要,因爲錯誤沒有發生在那裏。但是,如果你想看到他們,你只需要問。
現在,每次我嘗試做一些像
operations.insert(x) //assuming x is a struct that exists.
或
operations[i].key; //assuming i is a declared and initialized index.
它給我的error C2228: left of (fill in the blank) must have class/struct/union
和error C2109: subscript requires array or pointer type
我已經看到了這個問題以前線程,我認爲我的問題是編譯器將我提供的第一行代碼作爲聲明提供,但沒有初始化上。 但是我沒有看到解決方案。在我的腦海中,唯一的解決方法是使它成爲一個指針並使用= new ...
,但在我的腦海中,關鍵字new
是nastiness的同義詞,所以我只是想讓它成爲一個對象。什麼是解決這個問題的方法? 或者也許我錯了,這與對象類型是struct
有關,因爲這是我第一次與struct
s一起工作。
我愛的最棘手的解析。搜索這個詞,你會發現500個重複。 – chris
雖然你不需要提供所有的代碼,但是在這兩個例子中''操作的實際聲明都是重要的。 –
@chris你好,我讀了一堆,但很難看到我需要的答案。 – Yokhen