Вопрос по c++ – Как решить «чисто виртуальный метод называется»

18

Error: User Rate Limit Exceeded

pure virtual method called

SomeClass::~SomeClass()
{
   BaseClassObject->SomePureVirtualMethod(this);
}

void DerivedClass::SomePureVirtualMethod(SomeClass* obj)
{
    //Do stuff to remove obj from a collection
}

Error: User Rate Limit Exceedednew SomeClassError: User Rate Limit ExceededQList<SomeClass*>Error: User Rate Limit ExceededSomeClass*Error: User Rate Limit ExceededSomeClassError: User Rate Limit ExceededDerivedClassError: User Rate Limit ExceededSomeClassError: User Rate Limit ExceededQList<SomeClass*>.

Error: User Rate Limit Exceeded

BaseClass = Shape

DerivedClass = Triangle

SomeClass = ShapePropertiesError: User Rate Limit ExceededShape

Error: User Rate Limit Exceedednew ShapePropertiesError: User Rate Limit ExceededQList<ShapeProperties*>Error: User Rate Limit ExceededTriangleError: User Rate Limit ExceededShapePropertiesError: User Rate Limit ExceededTriangleError: User Rate Limit ExceededShapePropertiesError: User Rate Limit ExceededQList<ShapeProperties*>.

Ваш Ответ

2   ответа
8

virtualSomeClassSomePureVirtualMethod()SomeClass

Why does this happen?
this

Why does it crash?
Undefined Behavior.

C++03 10.4/6 states

"Member functions can be called from a constructor (or destructor) of an abstract class; the effect of making a virtual call (10.3) to a pure virtual function directly or indirectly for the object being created (or destroyed) from such a constructor (or destructor) is undefined."

How to avoid it?

virtual

29

SomePureVirtualMethod

Error: User Rate Limit ExceededthisError: User Rate Limit Exceeded user869525
Error: User Rate Limit ExceededSomePureVirtualMethodError: User Rate Limit Exceeded
Error: User Rate Limit ExceededSomePureVirtualMethodError: User Rate Limit Exceeded user869525
Error: User Rate Limit Exceeded
Error: User Rate Limit ExceededSomeClassError: User Rate Limit ExceededBaseClassError: User Rate Limit ExceededDerivedClass.SomeClassError: User Rate Limit ExceededBaseClassError: User Rate Limit ExceededDerivedClassError: User Rate Limit ExceededlistError: User Rate Limit ExceededSomeClassError: User Rate Limit ExceededSomeClassError: User Rate Limit ExceededSomeClassError: User Rate Limit ExceededlistError: User Rate Limit ExceededDerivedClass. user869525

Похожие вопросы