なぜこのエラーが発生するのかわかりません。クラス内のすべての関数が定義されています。私はTの中にも値を入れようとしましたが、何も起こりませんでした。私はこのエラーを受信し続ける:あなたがここに持ってしようとしているスタックの種類を決定する必要がありエラーC2955:クラステンプレートを使用するにはテンプレート引数リストが必要です
template< class T >
class Stack {
public:
Stack(int = 10); // default constructor (stack size 10)
// destructor
~Stack() {
delete[] stackPtr;
}
bool push(const T&);
bool pop(T&);
// determine whether Stack is empty
bool isEmpty() const {
return top == -1;
}
// determine whether Stack is full
bool isFull() const {
return top == size - 1;
}
private:
int size; // # of elements in the stack
int top; // location of the top element
T *stackPtr; // pointer to the stack
};
// constructor
template< class T >
Stack<T>::Stack(int s) {
size = s > 0 ? s : 10;
top = -1; // Stack initially empty
stackPtr = new T[size]; // allocate memory for elements
}
template< class T >
bool Stack<T>::push(const T &pushValue) {
if (!isFull()) {
stackPtr[++top] = pushValue;
return true;
}
return false;
}
template< class T >
bool Stack<T>::pop(T &popValue) {
if (!isEmpty()) {
popValue = stackPtr[top--]; // remove item from Stack
return true;
}
return false;
}
int main() {
Stack s();
}
あなたは* 'S'は何のスタック*になりたいなど? –
実際には、あなたは何のスタックを返すのですか? –