Close, but a temporary copy of the object is still an independent copy. C++ does not make reference copies of objects like Java or C#. To replace the object the iterator refers to, you need to assign to the dereferenced iterator. This will overwrite the object that it refers to:
bool updateListElement(Object* air)
{
std::list <Object>::iterator iObject;
for (iObject= list.begin(); iObject != list.end(); ++iObject)
{
Object temp = *iObject;
if (temp.getCode() == air->getCode())
{
*iObject = *air;
return true;
}
}
return false;
}
Reputation Points: 1446
Solved Threads: 135
Practically a Master Poster
Offline 681 posts
since Jun 2009