I'm trying to overload operator +. important to say, operator + gets exactly the datat I want it to get, but once i send it to operator=, all the pointers in it are deleted for some reason.
Movie& Movie:: operator+ (const Movie& other) {
Movie toReturn,toCheck;
Worker* toAdd;
std::list<Worker*>::iterator checkSecond;
length > other.getLength() ? toReturn=*this, toCheck=other : toReturn =
other , toCheck = *this;
//I WANT TO TAKE THE LONGER MOVIE, AND ADD THE WORKERS FROM THE SHORTER
MOVIE TO THAT MOVIE
if(toCheck.getNumOfWorkers() > 0 ) //LOOK FOR WORKERS IN SHORT MOVIE
{
for (checkSecond=toCheck.getWorkersInMovie().begin(); checkSecond !=
toCheck.getWorkersInMovie().end(); ++checkSecond)
{
toAdd= (*checkSecond);
toReturn.addWorker(toAdd);
toAdd = NULL;
} //END FOR
}
}
}
*this=toReturn;
cout << "this is what my new object has after +" <<endl;
this->printMovie(); //PRINTS EXACTLY WHAT I EXPECT, WITH NEW WORKERS
return *this;
}
but when i send it to operator = it doesn't get copied as expected, say the number of workers is 0. MOVIE BOTH = MOVIEFIRST + MOVIETOADD
Movie& Movie:: operator= (const Movie& other) {
WHEN IT GETS HERE, MOVIE OTHER GETS DELETED..
return *this;
}
copy constructor works as expected in all scenarios:
Movie::Movie(const Movie& toCopy) {
cout << "inside copy" << endl;
*this=toCopy;
}
HELP...?