我从我的程序中得到以下输出:
$ ./list
Enter list 1: [1,2,3,4]
[
Enter list 2: [2,5,8,0]
[
[1,2,3,4]
[1,2,3,4]
*** Error in `./list': double free or corruption (fasttop): 0x0000000000f85100 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x80a46)[0x7fa0368d6a46]
./list[0x400d5f]
./list[0x400c62]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7fa036877ea5]
./list[0x400ae9]
======= Memory map: ========
00400000-00402000 r-xp 00000000 ca:01 410613 /home/ubuntu/list
...
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
the endAborted (core dumped)
这就是我的主要内容:
int main(){
pennlist::List l1,l2;
cout<<"Enter list 1:\t";
cin>>l1;
cout<<"Enter list 2:\t";
cin>>l2;
cout<<l1<<endl<<l2<<endl;
cout<<"the end";
}
这是重载的 >> 运算符。
istream& operator >>(istream& ins, List& write_me){
char discard;
write_me.head = new node;
write_me.current = write_me.head;
node* temp = write_me.head;
ins>>discard;//get [
cout<<discard<<endl;
while(discard != ']'){
ins>>temp->data;
write_me.count += 1;
temp->to_tail = new node;
temp->to_head = temp;
temp = temp->to_tail;
ins>>discard; //get , or ]
}
write_me.tail = temp;
temp = NULL;
return ins;
}
我也重载了 =、~ 并复制 ctr,并在添加这些函数之前和之后得到相同的错误。
我不知道如何解决这个错误,请帮助。
编辑
Here is the code for the destructor:
~List{
delete head;
delete current;
delete tail;
}