_风雪夜归人_ 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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?