Code: Select all
#include "stdafx.h"
#include "stdio.h"
class a
{
public :
bool m_Dead;
a::a() { printf("a::a()\n"); init(); }
virtual a::~a() { printf("a::~a()\n"); cleanup(); }
virtual void init() { printf("a::init()\n"); m_Dead = false; }
virtual void cleanup() { printf("a::cleanup()\n"); testing(); }
virtual void testing() { printf("a::testing()\n"); }
};
class b : public a
{
public :
b::b() { printf(" b::b()\n"); init(); }
virtual b::~b() { printf(" b::~b()\n"); cleanup(); }
virtual void init() { printf(" b::init()\n"); }
virtual void cleanup() { printf(" b::cleanup()\n"); }
virtual void testing() { printf(" b::testing()\n"); }
};
#include <list>
using namespace std;
typedef std::list<a*> aList;
typedef aList::iterator aListIterator;
int _tmain(int argc, _TCHAR* argv[])
{
aList m_List;
b* testb = new b();
testb->m_Dead = true;
m_List.push_front(testb);
aListIterator i;
for (i = m_List.begin(); i != m_List.end(); )
{
if ( (*i)->m_Dead)
{
delete(*i);
i = m_List.erase(i);
}
else
{
++i;
}
}
while(getchar()!='q');
return 0;
}