简体   繁体   中英

malloc: *** error for object 0x10020a2c0: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug

My rest of the program is working fine except when I try to use the += operator in the main, it throws an error.Assignment 4(1643,0x10013c3c0) malloc: * error for object 0x10020a2c0: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug. Any help of how to fix it will be appreciated. This is the definition of my += function:

Student Student::operator+=(string item){
CheckOut(item);  //checkout is a member function of the class Student
return *this;

}

This is where the xcode compiler points the error at saying thread1: signal SIGABRT. I dont know what this error means.

Student::~Student(){
delete [] pointer; //it points error right here
pointer = NULL;

}

Your operator function should return a reference to Student:

Student& Student::operator+=(string item){ CheckOut(item); //checkout is a member function of the class Student return *this; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM