我在尝试使用此类编译时看到了六个错误
#include "stdafx.h"
#pragma once
#ifndef STACK_H
#define STACK_H
template <typename E>
class ArrayStack {
enum { DEF_CAPACITY = 100 }; // default stack capacity
public:
ArrayStack(int cap = DEF_CAPACITY); // constructor from capacity
int size() const; // number of items in the stack
bool empty() const; // is the stack empty?
const E& top() const throw(StackEmpty); // get the top element
void push(const E& e) throw(StackFull); // push element onto stack
void pop() throw(StackEmpty); // pop the stack
private:
E* S; // array of stack elements
int capacity; // stack capacity
int t; // index of the top of the stack
};
#endif
#include "stdafx.h"
#include "Stack.h"
template <typename E> ArrayStack<E>::ArrayStack(int cap): S(new E[cap]), capacity(cap), t(-1) { }
template <typename E>
int ArrayStack<E>::size() const {
return (t + 1);
}
template <typename E>
bool ArrayStack<E>::empty() const{
return (t < 0);
}
template <typename E>
const E& ArrayStack<E>::top() const throw(StackEmpty) {
if (empty()) throw StackEmpty("Top of empty stack");
return S[t];
}
template <typename E>
void ArrayStack<E>::push(const E& e) throw(StackFull) {
if (size() == capacity) throw StackFull("Push to full stack");
S[++t] = e;
}
template <typename E>
void ArrayStack<E>::pop() throw(StackEmpty) {
if (empty()) throw StackEmpty("Pop from empty stack");
--t;
}
这个特殊的课程是从我的教科书中复制到我不能使用标准库的学校项目,但我可以使用教科书(无论出于何种原因)。< / p>
如果有帮助的话,我对这个类的对象看起来像这样:
ArrayStack<char> postfixStack;