_风雪夜归人_ 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
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

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

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP