I'm editing this question to make it more readable and less contrived. I've managed to replicate my issue with the following short piece of code. The question, then, is: why does this crash on an assertion failure with _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) on the "delete p" line in ~A()?
class A;
class I
{
public:
I(const A *p) : parent_(p) {}
virtual void foo() = 0;
protected:
const A *parent_;
};
class I1 : public virtual I
{
public:
I1(const A *p) : I(p) {}
virtual void foo() {}
};
class A
{
public:
A() {}
virtual ~A()
{
for (size_t i = 0; i < it_.size(); ++i)
{
I *p = it_.at(i);
delete p;
}
}
virtual I* add() { I *p = new I1(this); it_.push_back(p); return p; }
protected:
vector<I*> it_;
};
int _tmain(int argc, _TCHAR* argv[])
{
A *a = new A();
for (int i = 0; i < 10; ++i) a->add();
delete a;
system("pause");
return 0;
}