0
votes

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;

}

1
I'm not sure what you're intending to do here, but SIGABRT is commonly used by some C++ libraries to abort the program in case of critical errors. For example, glibc sends an SIGABRT in case of a detected double-delete or other heap(heap is a memory used when you use new operator) corruptions. So in short, I think you are trying to free a memory which has already been deleted. - Zaid Khan

1 Answers

0
votes

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; }