_风雪夜归人_ 2017-09-03 12:10 采纳率: 0%
浏览 825

关于C++的对象数组的问题

代码如下,学习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;
}

  • 写回答

5条回答

  • 仅仅学会简单 2017-09-04 02:50
    关注

    你这复制出来的代码应该不全,都是你自己写的,单步调试看看

    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料