Without seeing the code causing the error, it's difficult to know exactly what's going on. If this is a compile-time error, I don't see anything here that would cause it.
However, if you're seeing a runtime error, the two most common causes of this that I can think of are:
(1) Calling the member function from within the base class's constructor or destructor (even indirectly).
(2) The derived class calling the base class's version of the function without it being implemented.
An example showing both of these errors would be:
struct Base {
Base()
{
call_foo(); // Oops, indirectly calls Base::foo() (Scenario 1)
}
void call_foo() const {
foo();
}
protected:
virtual void foo() const = 0;
};
struct Derived : Base {
protected:
virtual void foo() const {
Base::foo(); // Oops, unimplemented virtual base function (Scenario 2)
}
};
int main() {
Derived().call_foo();
}
== UPDATE: Possible compile-time error ==
I observe in your example code that record has a non-pure-virtual clone() member function returning a record *
. Since record is abstract, you can't create a record directly (only its concrete subclasses). This suggests that your clone() member function should probably also be pure virtual; if it tries to (for example) return new record()
, you will get an error that your base class has pure virtual functions.