C++程序运行时说出现一个问题,导致程序停止正常工作
出错的是这部分代码,可是找不到错哪SZYStringSZYString::operator+(SZYString&str2){size=size+20;char*news...
出错的是这部分代码,可是找不到错哪
SZYString SZYString::operator+(SZYString &str2){ size = size + 20;
char* newstr = new char[size]; for (int i = 0; i < end; i++) { newstr[i] = str[i]; } delete []str;
for (int j = end; j < (end + str2.end); j++) { newstr[j] = str2.str[j - end];
} str = new char[size]; for (int m = 0; m < (end + str2.end); m++) { str[m] = newstr[m]; } end = end + str2.end; delete newstr; return str;
构造函数是
SZYString::SZYString(const char* a)
{
end = 0;
for (int j = 0; a[j] != '\0'; j++) {
end += 1;
}
size = 20;
while (end >= size) {
size = size + 20;
}
str = new char[size];
for (int i = 0; a[i] != '\0'; i++) {
str[i] = a[i];
}
} 展开
SZYString SZYString::operator+(SZYString &str2){ size = size + 20;
char* newstr = new char[size]; for (int i = 0; i < end; i++) { newstr[i] = str[i]; } delete []str;
for (int j = end; j < (end + str2.end); j++) { newstr[j] = str2.str[j - end];
} str = new char[size]; for (int m = 0; m < (end + str2.end); m++) { str[m] = newstr[m]; } end = end + str2.end; delete newstr; return str;
构造函数是
SZYString::SZYString(const char* a)
{
end = 0;
for (int j = 0; a[j] != '\0'; j++) {
end += 1;
}
size = 20;
while (end >= size) {
size = size + 20;
}
str = new char[size];
for (int i = 0; a[i] != '\0'; i++) {
str[i] = a[i];
}
} 展开
1个回答
展开全部
SZYString SZYString::operator+(SZYString &str2){
size = size + 20;
char* newstr = new char[size];
for (int i = 0; i < end; i++) {
newstr[i] = str[i];
}
delete []str;//这句不需要的吧
for (int j = end; j < (end + str2.end); j++) {
newstr[j] = str2.str[j - end];
}
str = new char[size];
for (int m = 0; m < (end + str2.end); m++) {
str[m] = newstr[m];
}
end = end + str2.end;
delete newstr;//这句是不是delete[] newstr;
return str;
构造函数:
SZYString::SZYString(const char* a)
{
end = 0;
for (int j = 0; a[j] != '\0'; j++) {
end += 1;
}
size = 20;
while (end >= size) {
size = size + 20;//这句是不是该这样size = end + 20
}
str = new char[size];
for (int i = 0; a[i] != '\0'; i++) {
str[i] = a[i];
}
}
或者把你的代码发到我的邮箱 jhanker@163.com
size = size + 20;
char* newstr = new char[size];
for (int i = 0; i < end; i++) {
newstr[i] = str[i];
}
delete []str;//这句不需要的吧
for (int j = end; j < (end + str2.end); j++) {
newstr[j] = str2.str[j - end];
}
str = new char[size];
for (int m = 0; m < (end + str2.end); m++) {
str[m] = newstr[m];
}
end = end + str2.end;
delete newstr;//这句是不是delete[] newstr;
return str;
构造函数:
SZYString::SZYString(const char* a)
{
end = 0;
for (int j = 0; a[j] != '\0'; j++) {
end += 1;
}
size = 20;
while (end >= size) {
size = size + 20;//这句是不是该这样size = end + 20
}
str = new char[size];
for (int i = 0; a[i] != '\0'; i++) {
str[i] = a[i];
}
}
或者把你的代码发到我的邮箱 jhanker@163.com
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询