Hey guys,
Can anyone post sample code about updating an object that is already in an std::list? I know that it sounds as a really stupid question, but obviously I'm doing something wrong.
In my code I'm going through the list with an iterator until I reach the object of interest. My intention is to replace the current node in the list with another object.
The following snippet of code demonstrates that but I'm sure that I do something wrong in the if statement.
Thanks in advance..!
bool updateListElement(Object* air)
{
list <Object>::iterator iObject;
for (iObject= list.begin(); iObject != list.end(); ++iObject)
{
Object temp = *iObject;
if (temp.getCode() == air->getCode())
{
temp=*air;
return true;
}
}
return false;
}