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_
If you'd like to worry less about remembering to de-allocate the allocated memory (and have a nicer less error prone code) you should use unique_ptr or shared_ptr (read about them and shoose whichever fits your needs best).
Here is a small example (notice how the elements in the vector get deleted when the vector goes out of scope):
cout<<"Scope begins"< > v;
for (int i=0; i<5; ++i){
v.push_back(unique_ptr(new A(i)) );
}
}
cout<<"Scope ends"<
Live demo here.