I am slightly confused about the following code
void foo() {
std::list list;
for (int i = 0; i < 3; i ++) {
A a = A(i);
list.push_
You have a list of dangling pointers.
for (int i = 0; i < 3; i ++) {
A a = A(i);
list(&a);
}
In each iteration, this loop creates an object of type A, which is immediately destroyed when the iteration completes. So the contents of the list are undefined. You would need something like this:
for (int i = 0; i < 3; i ++) {
A* a = new A(i);
list(a);
}
...but don't forget to delete them all in another loop when you're done with the list.