C++ assertion error while deleting object
I have strange assertion error and I can not find what is wrong with this code. Assertion expression is _BLOCK_TYPE_IS_VALID(pHead->nBlockUse). I simplified code a bit for better readability. class Creator { public: virtual ~Creator() { for (MyObject* item : _list) { delete item; <-- assertion error here item = 0; } _list.clear(); } template <class T> T& create() { T * item = new T(); _list.push_back(item); return *item; } private: std::list<MyObject*> _list; }; class A : public MyObject, public Creator { }; class B : public MyObject, public Creator { }; int main() { A a; a.create<A>(); } <--