Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3.  
  4. using namespace std;
  5.  
  6. class A{
  7. public:
  8.     A(){
  9.         cout << "Created" << endl;
  10.     }
  11.     ~A(){
  12.         cout << "Deleted" << endl;
  13.     }
  14. };
  15.  
  16. int main(){
  17.     list<A*> lst;
  18.  
  19.     for(int i = 0; i < 10; i++)
  20.         lst.push_back(new A());
  21.     cout << "List size: " << lst.size() << endl;
  22.  
  23.     for(std::list<A*>::iterator it = lst.begin(); it != lst.end(); ++it){
  24.         delete *it;
  25.         it = lst.erase(it);
  26.     }
  27.  
  28.     cout << "List size: " << lst.size() << endl;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement