I am slightly confused about the following code
void foo() {
std::list<A*> list;
for (int i = 0; i < 3; i ++) {
A a = A(i);
list.push_back(&a);
}
for (Iterator it = list.begin(); it != list.end(); it++) {
std::cout << (*it);
}
}
which prints out three times the object a with constructor argument 2, i.e. the last object constructed in the loop.
What am I doing wrong here?