I know that it isn't possible to have class methods that are both pure virtual and static (see this discussion). So, I ask: is there a way to guarantee that a bunch of derived classes have static functions that do the same thing and that are guaranteed to be named in the same way?
Consider the following example:
#include <iostream>
#include <array>
// class base {
// public:
// virtual static constexpr size_t nums() = 0
// }
template<size_t num>
class derived1 {//: public base {
public:
static constexpr size_t nums() {return num;}
derived1() {}
};
template<size_t num>
class derived2 {// : public base {
public:
static constexpr size_t nums() {return num;}
derived2() {}
};
int main() {
std::cout << derived2<20>::nums() << "\n";
return 0;
}
I commented out the base class so that it compiles, but I want an interface class that guarantees a bunch of derived classes all have nums()
named in the same way. In this particular example nums
is named the same way in both derived class, but if I write a third derived class a few years from now, and I forget this convention, I don't want to be able to compile anything, ideally.