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

C++string类对象数组的问题

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;
}

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-20 19:21
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决
  • ¥15 关于华为5g模块mh5000-31接线问题
  • ¥15 keil L6007U报错
  • ¥15 webapi 发布到iis后无法访问
  • ¥15 初学者如何快速上手学习stm32?