object = *i;
makes a copy of the object in the list. you modify and output the copy in the first loop and make and output a new copy in the second loop
this one should do it:
Code:
for (i = objects.begin(); i != objects.end(); i++) {
i->setValue(9);
cout << i->getValue() << endl;
}
cout << "====" << endl;
for (i = objects.begin(); i != objects.end(); i++) {
cout << i->getValue() << endl;
}
also it would be better to minimize the scope of your vars, for example like that:
Code:
for ( list<Object>::iterator i = objects.begin(); i != objects.end(); i++) {
instead of declaring i outside the for-loop. that could lead to unwanted sideeffects later