【发布时间】:2012-05-29 06:06:06
【问题描述】:
我明白为什么会发生这种情况,但我一直在尝试解决它...这是我的代码在我的程序退出时生成错误(因此导致崩溃)时所做的事情...
pure virtual method called
SomeClass::~SomeClass()
{
BaseClassObject->SomePureVirtualMethod(this);
}
void DerivedClass::SomePureVirtualMethod(SomeClass* obj)
{
//Do stuff to remove obj from a collection
}
我从来没有打电话给new SomeClass,但我有一个QList<SomeClass*>,我将SomeClass*对象附加到它上面。 SomeClass 中的这个析构函数的目的是告诉DerivedClass 从它的QList<SomeClass*> 集合中删除SomeClass 的特定实例。
所以,举个具体的例子……
BaseClass = Shape
DerivedClass = Triangle
SomeClass = ShapeProperties 拥有对 Shape 的引用
所以,我从来没有打电话给new ShapeProperties,但我在Triangle 中有一个QList<ShapeProperties*>。 ShapeProperties 中的析构函数是告诉Triangle 从QList<ShapeProperties*> 的集合中删除ShapeProperties 的特定属性。
【问题讨论】:
标签: c++ polymorphism derived-class base-class pure-virtual