gpt4 book ai didi

c++ - 我在返回过程中遇到错误 255

转载 作者:行者123 更新时间:2023-11-28 06:18:11 26 4
gpt4 key购买 nike

<分区>

#include<iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

int const MAX=10;
class Order{
int number;
char** ord;
int capacity;
int top;
public:
Order();
Order(Order const&);
Order (int);
~Order();
bool full() const { return top==capacity;}
bool empty()const { return top<=0; }
Order& operator=(Order const&);
void addItem1(const char*);
void cancel();
void Resize();
friend ostream& operator<<(ostream& os,Order const& q);
};

Order::Order(){
number=0;
ord=NULL;
capacity=MAX;
top=0;
}
Order::Order(Order const& w):number(w.number),ord(NULL),
top(w.top),capacity(w.capacity)
{
ord = new char*[top];
for(int i=0;i<top;i++){
int k=strlen(w.ord[i])+1;
ord[i]=new char[k];
strncpy(ord[i],w.ord[i],k);
ord[i][k-1]='\0';
}
}
Order::Order(int x):ord(NULL),top(0),capacity(MAX){
number=x;
}
Order& Order::operator=(Order const& w){
if(this!=&w){
cancel();
ord = new char*[top];
for(int i=0;i<w.top;i++){
int k=strlen(w.ord[i])+1;
ord[i]=new char[k];
strncpy(ord[i],w.ord[i],k);
ord[i][k-1]='\0';
}
number=w.number;
top=w.top;
capacity=w.capacity;
return *this;
}
}
void Order::Resize(){
size_t Newcapacity=capacity*3/2+1;
char** tmp=new char*[Newcapacity];
for(int i=0;i<capacity;i++){
size_t s=strlen(ord[i])+1;
tmp[i]=new char[s];
strncpy(tmp[i],ord[i],s);
tmp[i][s-1]='\0';
}
for(int i=0;i<capacity;i++)
delete[]ord[i];
delete[] ord;

capacity=Newcapacity;
ord=tmp;
}
void Order::addItem1(const char* disc){
//if(full())
// Resize();
size_t p=strlen(disc)+1;
ord[top]=new char[p];
strncpy(ord[top],disc,p);
ord[top][p-1]='\0';

top++;
}
void Order::cancel(){
if(!empty()){
for(int i=0;i<capacity;i++)
delete[] ord[i];
delete[]ord;
capacity=MAX;
top=0;
ord=NULL;
}
}
Order::~Order(){
cancel();
number=0;
}
ostream& operator<<(ostream& os,Order const& t){
os<<t.number<<endl;
for(int i=0;i<t.top;i++){
os<<i<<". "<<t.ord[i]<<endl;
}
return os;
}
int main(){
int s1=257;
int s2=245;
int s3=244;
char S1[20]="Pile s oriz";
char S2[20]="Krem karamel";
char S3[20]="Salata";
Order p(s1);
p.addItem1(S1);
//p.addItem(S3);
//Order q(p);
//q.addItem(S2);
cout<<"First: "<<p<<endl;
//cout<<"Second: "<<q<<endl;
return 0;
}

我不知道哪里出错了,能帮帮我吗?如果这很重要,我会使用 Code::Blocks 10.05。

0 errors, 0 warningsChecking for existence: C:\Users\user1\Downloads\Нова папка\wtfff.exeExecuting: C:\Program Files (x86)\CodeBlocks/cb_console_runner.exe "C:\Users\user1\Downloads\Нова папка\wtfff.exe" (in C:\Users\user1\Downloads\Нова папка)Process terminated with status -1073741510 (0 minutes, 8 seconds)

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com