#include <cstdio>
#include <list>
using namespace std;
int main()
{
list<int> m_List;
m_List.push_back(10);
m_List.push_back(20);
//travel list
list<int>::iterator i = m_List.begin();
for (i = m_List.begin(); i != m_List.end(); i++)
{
printf("%d\n", *i);
}
return 0;
}
class Element
{
int ID;
public:
Element(int id)
{
printf("Created %d at 0x%x\n", id, this);
ID = id;
}
~Element()
{
printf("Destroy %d at 0x%x\n", ID, this);
}
};
int main()
{
Element e1(0), e2(1);
list<Element> m_List;
//add to list
m_List.push_back(e1); m_List.push_back(e2);
//clear list
printf("-----Before clear-----\n");
m_List.clear();
printf("-----After clear-----\n");
return 0;
}
class Element {
int ID;
public:
Element(int id)
{
printf("Created %d at 0x%x\n", id, this);
ID = id;
}
~Element()
{
printf("Destroy %d at 0x%x\n", ID, this);
}
};
int main() {
list<Element*> m_List;
Element *e0 = new Element(0);
Element *e1 = new Element(1);
//add to list
m_List.push_back(e0); m_List.push_back(e1);
//clear list
printf("-----Before clear-----\n");
m_List.clear();
printf("-----After clear-----\n");
return 0;
}
int main()
{
list<Element*> m_List;
Element *e0 = new Element(0);
Element *e1 = new Element(1);
//add to list
m_List.push_back(e0);
m_List.push_back(e1);
//clear list
printf("-----Before clear-----\n");
list <Element*>::iterator i;
for (i = m_List.begin(); i != m_List.end(); i++)
{
delete *i;
}
m_List.clear();
printf("-----After clear-----\n");
return 0;
}