我正在尝试编译下一个代码,但在指示的行上出现此错误
“数组下标的无效类型‘int [int]’”
代码:
template<typename T>
class Stack {
private:
static const int GROW_FACTOR = 2;
static const int START_LENGHT = 10;
T * data;
int max;
int used;
void allocateIfNeeded() {
if (used == max) {
T * aux = new T[max*GROW_FACTOR];
for (int i=0; i<max; i++) {
aux[i] = data[i];
}
max *= GROW_FACTOR;
delete[] data;
data = aux;
}
}
public:
Stack() {
max = START_LENGHT;
data = new T[max];
used = 0;
}
void push(T data) {
allocateIfNeeded();
data[used++] = data; // <-- compile error
}
T pop() {
return data[--used];
}
T top() {
return data[used-1];
}
bool isEmpty() {
return used == 0;
}
};
当出现此错误消息时,我已经检查了其他情况,但我认为它们与此无关。