Объясните, пожалуйста, из-за чего может возникать
run-time error: pure virtual function call?
Вроде С++ не допускает вызова чистых вирт. функций...
При этом все прекрасно компилится и линкуется...
pure virtual function call
Модераторы: Hawk, Romeo, Absurd, DeeJayC, WinMain
Компилятор С++, конечно, не допускает явного вызова чистовиртуальных функций, но он не может отследить случаи, когда такой вызов происходит неявно. Вот пример из MSDN, демонстрирующий подобную ситуацию:
Код: Выделить всё
class A;
void fcn( A* );
class A
{
public:
virtual void f() = 0;
A() { fcn( this ); }
};
class B : A
{
void f() { }
};
void fcn( A* p )
{
p->f();
}
// The declaration below invokes class B's constructor, which
// first calls class A's constructor, which calls fcn. Then
// fcn calls A::f, which is a pure virtual function, and
// this causes the run-time error. B has not been constructed
// at this point, so the B::f cannot be called. You would not
// want it to be called because it could depend on something
// in B that has not been initialized yet.
B b;
void main()
{
}