自定义了一个类,类的成员函数都已实现,但在测试时出现问题,结果发现是犯了一个低级错误,出现的错误是:
error: request for member 'push' in 'sl', which is of non-class type 'stackList()'
源码:
template
class stackList : public stack {
public:
//构造函数
stackList();
stackList(const stackList &sl);
//栈操作
virtual void deleteAllValues();
virtual int isEmpty() const;
virtual T pop();
virtual void push(T value);
virtual T top() const;
protected:
list data;
};
template
stackList::stackList():data(){
}
template
stackList::stackList(const stackList&v):data(v.data){
}
template
T stackList::pop() {
assert(!isEmpty()); //判断栈的下溢
T result=data.firstElement();
data.removeFirst();
return result;
}
template
void stackList::push(T value) {
data.add(value);
}
//其他代码略
调用测试代码:
int main(int argc, char** argv) {
stackList sl(); //低级错误在这里,应该是stackList sl;
sl.push(189);
cout<
return 0;
}
备忘!
阅读(9103) | 评论(0) | 转发(0) |