2 ms·
Yes, I think in C++ at-least you are supposed to protect from this by never having the child directly implement the virtual method. This means inheritors only
by cjhanks 8y ago
Yes, I think in C++ at-least you are supposed to protect from this by never having the child directly implement the virtual method.
This means inheritors only need to ensure they implement according to the specified constraints.
I also suspect some of the new C++14 and beyond meta tagging can even enforce a `final`.
class Abstract {
public:
// Even though this function might do nothing but
// redirect, it is a useful abstraction.
void
SomeMethod() {
// Do things which must be done first, if any.
ImplSomeMethod();
// Do things which must be done after, if any.
}
protected:
// Document all expected invariant behavior here.
virtual void
ImplSomeMethod() = 0;
};
- tomjakubowski 8y agoC++11 added final for both virtual member functions and for classes. No need for C++2x metaclasses.
- cjhanks 8y agoSorry, what are the C++2x metaclasses? I haven't been following along very closely.