sage of stackoverflow。問題は、で記述されています。LIST_ENTRYが壊れています(つまり、二重削除)エラーです。しかし、私はどこに間違っているのか分かりません。コンストラクタにメモリを割り当てて、そのメモリを私のデストラクタのオペレータdelete[]
で解放しました。これ以上のメモリ除去は起こりません。だから問題は何ですか。 コード:
LIST_ENTRYがC++で破損しています(つまり、ダブル・アンロード)
String():str(NULL), length(0)
{
str=new char [100];
cout<<"Default constructor has been used"<<endl;}
String(const char* ko)
{
str=new char [strlen(ko)];
strcpy(str,ko);
cout<<endl;
length=strlen(ko);
cout<<"The object is initialized"<<endl;
}
String(String &y)
{
length=y.length;
str=new char[length];
strcpy(str,y.str);
cout<<endl;
}
デストラクタ:
~String()
{
length=0;
char* spp=str+1;
delete[] str;/*Here is the point of error(btw if get this operator out the code the programm works fine)*/
str=NULL;
cout<<spp;
}
strlen()バイトを割り当ててstrcpy()を使用すると、割り当てられたメモリに1バイト以上書き込んだとします。あなたは壊れたヒープを持っています。 –