#include<iostream>using namespace std;template<class Type>class Stack{private:int top;Type *stacka;//用數組存儲棧的元素int maxSize;public:Stack(int Size);//~Stack(){delete[] stack;}void push(const Type &item);Type pop(void);Type getTop();int empty(void) const{return top==-1;}int full(void) const{return maxSize-1;}void clear(void){top==-1;}};template<class Type>void Stack<Type> ::push(const Type &item){if(full()){cout<<"stack is full"<<endl;exit(1);}top++;stacka[top]=item;}template<class Type>Type Stack<Type> ::pop(){if(empty()){cout<<"stack is empty!"<<endl;exit(1);}Type data=stacka[top];//棧不空,取棧頂元素top--;return 0;//返回棧頂元素}template<class Type>Type Stack<Type> ::getTop(){if(empty()){cout<<"stack is empty!"<<endl;exit(1);}return stacka[top];//棧不空,取棧頂元素}int main(){typedef Stack<int> IntStack;IntStack s;for(int i=0;i<10;i++){s.push(i);}for(int i=0;i<10;i++){cout<<"翻轉后:"<<s.pop()<<endl;}}報錯是45 cpp no matching function for call to `Stack<int>::Stack()'cpp:4 candidates are: Stack<int>::Stack(const Stack<int>&)
添加回答
舉報
0/150
提交
取消