There are a few functions with this problem, but a good example of one is at line 248. That function is intended to receive 2 arguments (a playlist object, which includes an array of songs, and a song object, which includes 2 strings) and return 1 variable (a playlist object that equals the inputted song added to the inputted playlist). When I run this function, I get an error saying:
Windows has trigged a breakpoint in Project 2.exe.
This may be due to a corruption of the heap, which indicates a bug in Project 2.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while Project 2.exe has focus.
The output window may have more diagnostic information.
I've been working on this program for days, and can't figure this out. Any help would be MUCH appreciated.
Yes, you're right, but why is that happening? I'm attempting to allocate an array of 3 objects that each have 2 strings. Shouldn't be anywhere close to 4 gigs. Am I not using the destructor correctly? What haven't I destructed that should be?
Edit: The problem seems to be in the assignment overload. ListSize (an int in the PlayList class) returns a ridiculous number in that function...maybe there's some sort of scope problem?
PlayList& PlayList::operator=(const PlayList &p) {
//Assignment operator (p1 = p2)
cout << "*" << p.PlayPtr[0] << endl;
if (this!=&p) { //if the items aren't the same
Song *s=new Song[p.ListSize]; //allocate new array of p's size
this->ListSize=p.ListSize;
this->index=p.index;
this->Mode=p.Mode;
delete [] this->PlayPtr; //deallocate memory in this->PlayPtr
//copy elements in inputted array into new array
for (int i=0; i<p.ListSize; i++) s[i]=p.PlayPtr[i];
this->PlayPtr=s; //copy new array into old spot
}
return *this;
}
The variable initializes in the constructor, along with all the other variables of that class. Furthermore, NONE of the variables inside the class are accessible in the operator.
I can not for the life of me figure out why.
BTW the program takes the result of another function of the class (an overloaded addition operator) and uses it as the argument in the assignment operator.
I was about to ask the same thing guestgulkan. You should be editing/constructing the PlayList pointed to by this. You never initialize any of your playlist's fields.