fork download
  1. #include <iostream>
  2. #include <list>
  3.  
  4. using namespace std;
  5.  
  6. class Foo
  7. {
  8. public:
  9. Foo(){}
  10. ~Foo()
  11. {
  12. cout << "Destructor\n";
  13.  
  14. }
  15. };
  16.  
  17. int main()
  18. {
  19. Foo *a = new Foo();
  20. Foo *b = new Foo();
  21.  
  22. list<Foo*> myFoo;
  23. myFoo.push_back(a);
  24. myFoo.push_back(b);
  25.  
  26. list<Foo*>::iterator it;
  27.  
  28. for (it = myFoo.begin(); it != myFoo.end(); it++)
  29. delete (*it);
  30.  
  31. myFoo.clear();
  32.  
  33. }
Success #stdin #stdout 0.02s 2812KB
stdin
Standard input is empty
stdout
Destructor
Destructor