TITLE: Calling pure virtual methods


PROBLEM: ???

Objects of classes with pure virtual functions can't be created.


RESPONSE: Andrew.Dalgleish@f387.n634.z3.fidonet.org (Andrew Dalgleish)

Don't kid yourself!
Macroshaft run-time error R6025 "pure virtual function call"


RESPONSE: clamage@Eng.Sun.COM (Steve Clamage), 10 Sept 94

The error means that you managed to call a function declared to be pure virtual
via the virtual function mechanism. This is always an error, even if the
function is defined.

The error does not mean that an object of abstract type was created. I provide
an example below. The key error is calling a function from the abstract-class
constructor which in turn calls a function which is pure virtual in the
abstract class.

class PV { // abstract class
public:
    virtual void foo() = 0;
    PV();
};

void middleman(PV* p) { p->foo(); } // OK if p points to a concrete class

PV::PV() { middleman(this); }

class Der : public PV {	// concrete class
public:
    virtual void foo();	// implemented here
    Der();
};
Der::Der() { }
void Der::foo() { }


main()
{
    Der d;
    return 0;
}


