How can I protect against accidentally defining a non-inherited method where the inherited definition is intended. I am told that there is a trick to express it, but no one can remember it.
Explanation. I have a class tree: "Base" <- 'C' <- 'D', below. The base defines a pure virtual function. The function is redefined in C and then in D. But the function has a very long list of arguments.
Somewhere along the derivation chain in agrglist there is a subtle mistake that makes D :: non-inherited. The program is flexibly compiled. And the wrong method is called at runtime.
Is there a trick to cause a compilation error when the method is not inherited.
#include <iostream>
class Base {
public:
virtual void VeryLongFunctionName(int VeryLongArgumentList) = 0;
};
class C : public Base {
public:
void VeryLongFunctionName(int VeryLongArgumentList) {
std::cout << "C::\n";
}
};
class D : public C {
public:
void VeryLongFunctionNane(int VeryLongArgumentList) {
std::cout << "D::\n";
}
};
int main() {
Base *p = new D;
p->VeryLongFunctionName(0);
return 0;
}