Consider this:
struct Base {
virtual void fn() = 0;
};
struct A: Base {
virtual void fn();
};
struct B: A {
// fn is not overridden here
};
Basically, fn
is implemented in A
. B
derives from A
, and B
doesn't override fn
.
I'd like to have technique to make B
must override fn
, because it is an error, if it is not overridden.
Is is possible to do this? A compile-time error (or maybe warning) would be the best, but if it is not possible, then a runtime error is OK too. I'd just like to know, if someone forgets to override fn
in a derived class.
The reason for this? fn
could return class-related information. For example, it could return the class name. Or it could return the amount of allocated space the object uses (for debug purposes). Or do some class-related task (for example, loading/saving its state).