代码如下,学习C++的时候写的,在运行到abc.push(a)的时候崩溃了,请问有可能是什么原因?
#include
#include
#include
#include
using namespace std;
template
class stack{
private:
int maxSize;
int size;
int top;
type* content;
public:
stack();
bool isEmpty();
bool isFull();
bool push(const type & item);
bool pop(type& item);
virtual ~stack();
};
template
stack::stack(){
top = 0;
size = 0;
maxSize = 10;
type* content = new type10;
}
template
stack::~stack(){
delete [] content;
}
template
bool stack::isEmpty(){
return top == 0;
}
template
bool stack::isFull(){
return top == maxSize;
}
template
bool stack::push(const type& item){
if(this->isFull()){
return false;
}else{
content[top++] = item;
return true;
}
}
template
bool stack::pop(type& item){
if(this->isEmpty()){
return false;
}else{
item = content[--top];
return true;
}
}
int main(void){
stack abc;
string a = "abcdefg";
abc.push(a);
cout << abc.isEmpty() << endl;
cout << abc.isFull() << endl;
return 0;
}