所以我有这样一行:左侧的[填空]必须有类/结构/联合错误
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